Changeset 710 for box/chris/merge/test/win32
- Timestamp:
- 28/07/2006 00:18:35 (6 years ago)
- File:
-
- 1 edited
-
box/chris/merge/test/win32/testlibwin32.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/chris/merge/test/win32/testlibwin32.cpp
r456 r710 6 6 7 7 #ifdef WIN32 8 9 #include <assert.h> 10 #include <AccCtrl.h> 11 #include <Aclapi.h> 8 12 9 13 #include "../../bin/bbackupd/BackupDaemon.h" … … 13 17 int main(int argc, char* argv[]) 14 18 { 19 // ACL tests 20 char* exename = getenv("WINDIR"); 21 22 PSID psidOwner; 23 PSID psidGroup; 24 PACL pDacl; 25 PSECURITY_DESCRIPTOR pSecurityDesc; 26 27 DWORD result = GetNamedSecurityInfo( 28 exename, // pObjectName 29 SE_FILE_OBJECT, // ObjectType 30 DACL_SECURITY_INFORMATION | // SecurityInfo 31 GROUP_SECURITY_INFORMATION | 32 OWNER_SECURITY_INFORMATION, 33 &psidOwner, // ppsidOwner, 34 &psidGroup, // ppsidGroup, 35 &pDacl, // ppDacl, 36 NULL, // ppSacl, 37 &pSecurityDesc // ppSecurityDescriptor 38 ); 39 if (result != ERROR_SUCCESS) 40 { 41 printf("Error getting security info for '%s': error %d", 42 exename, result); 43 } 44 assert(result == ERROR_SUCCESS); 45 46 char namebuf[1024]; 47 char domainbuf[1024]; 48 SID_NAME_USE nametype; 49 DWORD namelen = sizeof(namebuf); 50 DWORD domainlen = sizeof(domainbuf); 51 52 assert(LookupAccountSid(NULL, psidOwner, namebuf, &namelen, 53 domainbuf, &domainlen, &nametype)); 54 55 printf("Owner:\n"); 56 printf("User name: %s\n", namebuf); 57 printf("Domain name: %s\n", domainbuf); 58 printf("Name type: %d\n", nametype); 59 printf("\n"); 60 61 namelen = sizeof(namebuf); 62 domainlen = sizeof(domainbuf); 63 64 assert(LookupAccountSid(NULL, psidGroup, namebuf, &namelen, 65 domainbuf, &domainlen, &nametype)); 66 67 printf("Group:\n"); 68 printf("User name: %s\n", namebuf); 69 printf("Domain name: %s\n", domainbuf); 70 printf("Name type: %d\n", nametype); 71 printf("\n"); 72 73 ULONG numEntries; 74 PEXPLICIT_ACCESS pEntries; 75 result = GetExplicitEntriesFromAcl 76 ( 77 pDacl, // pAcl 78 &numEntries, // pcCountOfExplicitEntries, 79 &pEntries // pListOfExplicitEntries 80 ); 81 assert(result == ERROR_SUCCESS); 82 83 printf("Found %lu explicit DACL entries for '%s'\n\n", 84 (unsigned long)numEntries, exename); 85 86 for (ULONG i = 0; i < numEntries; i++) 87 { 88 EXPLICIT_ACCESS* pEntry = &(pEntries[i]); 89 printf("DACL entry %lu:\n", (unsigned long)i); 90 91 DWORD perms = pEntry->grfAccessPermissions; 92 printf(" Access permissions: ", perms); 93 94 #define PRINT_PERM(name) \ 95 if (perms & name) \ 96 { \ 97 printf(#name " "); \ 98 perms &= ~name; \ 99 } 100 101 PRINT_PERM(FILE_ADD_FILE); 102 PRINT_PERM(FILE_ADD_SUBDIRECTORY); 103 PRINT_PERM(FILE_ALL_ACCESS); 104 PRINT_PERM(FILE_APPEND_DATA); 105 PRINT_PERM(FILE_CREATE_PIPE_INSTANCE); 106 PRINT_PERM(FILE_DELETE_CHILD); 107 PRINT_PERM(FILE_EXECUTE); 108 PRINT_PERM(FILE_LIST_DIRECTORY); 109 PRINT_PERM(FILE_READ_ATTRIBUTES); 110 PRINT_PERM(FILE_READ_DATA); 111 PRINT_PERM(FILE_READ_EA); 112 PRINT_PERM(FILE_TRAVERSE); 113 PRINT_PERM(FILE_WRITE_ATTRIBUTES); 114 PRINT_PERM(FILE_WRITE_DATA); 115 PRINT_PERM(FILE_WRITE_EA); 116 PRINT_PERM(STANDARD_RIGHTS_READ); 117 PRINT_PERM(STANDARD_RIGHTS_WRITE); 118 PRINT_PERM(SYNCHRONIZE); 119 PRINT_PERM(DELETE); 120 PRINT_PERM(READ_CONTROL); 121 PRINT_PERM(WRITE_DAC); 122 PRINT_PERM(WRITE_OWNER); 123 PRINT_PERM(MAXIMUM_ALLOWED); 124 PRINT_PERM(GENERIC_ALL); 125 PRINT_PERM(GENERIC_EXECUTE); 126 PRINT_PERM(GENERIC_WRITE); 127 PRINT_PERM(GENERIC_READ); 128 printf("\n"); 129 130 if (perms) 131 { 132 printf(" Bits left over: %08x\n", perms); 133 } 134 assert(!perms); 135 136 printf(" Access mode: "); 137 switch(pEntry->grfAccessMode) 138 { 139 case NOT_USED_ACCESS: 140 printf("NOT_USED_ACCESS\n"); break; 141 case GRANT_ACCESS: 142 printf("GRANT_ACCESS\n"); break; 143 case DENY_ACCESS: 144 printf("DENY_ACCESS\n"); break; 145 case REVOKE_ACCESS: 146 printf("REVOKE_ACCESS\n"); break; 147 case SET_AUDIT_SUCCESS: 148 printf("SET_AUDIT_SUCCESS\n"); break; 149 case SET_AUDIT_FAILURE: 150 printf("SET_AUDIT_FAILURE\n"); break; 151 default: 152 printf("Unknown (%08x)\n", pEntry->grfAccessMode); 153 } 154 155 printf(" Trustee: "); 156 assert(pEntry->Trustee.pMultipleTrustee == NULL); 157 assert(pEntry->Trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE); 158 switch(pEntry->Trustee.TrusteeForm) 159 { 160 case TRUSTEE_IS_SID: 161 { 162 PSID trusteeSid = (PSID)(pEntry->Trustee.ptstrName); 163 164 namelen = sizeof(namebuf); 165 domainlen = sizeof(domainbuf); 166 167 assert(LookupAccountSid(NULL, trusteeSid, namebuf, &namelen, 168 domainbuf, &domainlen, &nametype)); 169 170 printf("SID of %s\\%s (%d)\n", domainbuf, namebuf, nametype); 171 } 172 break; 173 case TRUSTEE_IS_NAME: 174 printf("Name\n"); break; 175 case TRUSTEE_BAD_FORM: 176 printf("Bad form\n"); assert(0); 177 case TRUSTEE_IS_OBJECTS_AND_SID: 178 printf("Objects and SID\n"); break; 179 case TRUSTEE_IS_OBJECTS_AND_NAME: 180 printf("Objects and name\n"); break; 181 default: 182 printf("Unknown form\n"); assert(0); 183 } 184 185 printf(" Trustee type: "); 186 switch(pEntry->Trustee.TrusteeType) 187 { 188 case TRUSTEE_IS_UNKNOWN: 189 printf("Unknown type.\n"); break; 190 case TRUSTEE_IS_USER: 191 printf("User\n"); break; 192 case TRUSTEE_IS_GROUP: 193 printf("Group\n"); break; 194 case TRUSTEE_IS_DOMAIN: 195 printf("Domain\n"); break; 196 case TRUSTEE_IS_ALIAS: 197 printf("Alias\n"); break; 198 case TRUSTEE_IS_WELL_KNOWN_GROUP: 199 printf("Well-known group\n"); break; 200 case TRUSTEE_IS_DELETED: 201 printf("Deleted account\n"); break; 202 case TRUSTEE_IS_INVALID: 203 printf("Invalid trustee type\n"); break; 204 case TRUSTEE_IS_COMPUTER: 205 printf("Computer\n"); break; 206 default: 207 printf("Unknown type %d\n", pEntry->Trustee.TrusteeType); 208 assert(0); 209 } 210 211 printf("\n"); 212 } 213 214 assert(LocalFree((HLOCAL)pEntries) == 0); 215 assert(LocalFree((HLOCAL)pSecurityDesc) == 0); 216 15 217 chdir("c:\\tmp"); 16 218 openfile("test", O_CREAT, 0); … … 26 228 { 27 229 info = readdir(ourDir); 28 if ( info) printf("File/Dir name is : %s\r\n", info->d_name);29 30 }while ( info != NULL);230 if (info) printf("File/Dir name is : %s\r\n", info->d_name); 231 } 232 while (info != NULL); 31 233 32 234 closedir(ourDir); 33 34 235 } 35 236 … … 42 243 { 43 244 info = readdir(ourDir); 44 if ( info == NULL) break;245 if (info == NULL) break; 45 246 std::string file(diry + info->d_name); 46 247 stat(file.c_str(), &ourfs); 47 if ( info) printf("File/Dir name is : %s\r\n", info->d_name);48 49 }while ( info != NULL );248 if (info) printf("File/Dir name is : %s\r\n", info->d_name); 249 } 250 while ( info != NULL ); 50 251 51 252 closedir(ourDir); … … 55 256 stat("c:\\windows", &ourfs); 56 257 stat("c:\\autoexec.bat", &ourfs); 57 printf("Finished dir read"); 58 #if 0 59 //remove - sleepycat include a version of getopt - mine never REALLY worked ! 258 printf("Finished dir read\n"); 259 60 260 //test our getopt function 61 std::string commline("-q -c fgfgfg -f -l hello"); 62 63 int c; 64 while((c = getopt(commline.size(), (char * const *)commline.c_str(), "qwc:l:")) != -1) 65 { 66 printf("switch = %c, param is %s\r\n", c, optarg); 67 } 68 #endif 261 char * test_argv[] = 262 { 263 "foobar.exe", 264 "-qwc", 265 "-", 266 "-c", 267 "fgfgfg", 268 "-f", 269 "-l", 270 "hello", 271 "-", 272 "force-sync", 273 NULL 274 }; 275 int test_argc; 276 for (test_argc = 0; test_argv[test_argc]; test_argc++) { } 277 const char* opts = "qwc:l:"; 278 279 assert(getopt(test_argc, test_argv, opts) == 'q'); 280 assert(getopt(test_argc, test_argv, opts) == 'w'); 281 assert(getopt(test_argc, test_argv, opts) == 'c'); 282 assert(strcmp(optarg, "-") == 0); 283 assert(getopt(test_argc, test_argv, opts) == 'c'); 284 assert(strcmp(optarg, "fgfgfg") == 0); 285 assert(getopt(test_argc, test_argv, opts) == '?'); 286 assert(optopt == 'f'); 287 assert(getopt(test_argc, test_argv, opts) == 'l'); 288 assert(strcmp(optarg, "hello") == 0); 289 assert(getopt(test_argc, test_argv, opts) == -1); 290 // assert(optopt == 0); // no more options 291 assert(strcmp(test_argv[optind], "-") == 0); 292 assert(strcmp(test_argv[optind+1], "force-sync") == 0); 69 293 //end of getopt test 70 294 71 295 //now test our statfs funct 72 296 stat("c:\\cert.cer", &ourfs); 73 74 75 297 76 298 char *timee; … … 78 300 timee = ctime(&ourfs.st_mtime); 79 301 80 if ( S_ISREG(ourfs.st_mode))81 { 82 printf("is a normal file ");302 if (S_ISREG(ourfs.st_mode)) 303 { 304 printf("is a normal file\n"); 83 305 } 84 306 else 85 307 { 86 printf("is a directory?"); 87 } 88 89 lstat("c:\\windows", &ourfs); 308 printf("is a directory?\n"); 309 exit(1); 310 } 311 312 lstat(getenv("WINDIR"), &ourfs); 90 313 91 314 if ( S_ISDIR(ourfs.st_mode)) 92 315 { 93 printf("is a directory ");316 printf("is a directory\n"); 94 317 } 95 318 else 96 319 { 97 printf("is a file?"); 320 printf("is a file?\n"); 321 exit(1); 98 322 } 99 323 … … 106 330 closelog(); 107 331 332 /* 108 333 //first off get the path name for the default 109 334 char buf[MAX_PATH]; … … 113 338 std::string conf("-c " + buffer.substr(0,(buffer.find("win32test.exe"))) + "bbackupd.conf"); 114 339 //std::string conf( "-c " + buffer.substr(0,(buffer.find("bbackupd.exe"))) + "bbackupd.conf"); 115 340 */ 116 341 117 342 return 0;
Note: See TracChangeset
for help on using the changeset viewer.
