Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

dumpuser.c

Go to the documentation of this file.
00001 00002 /* Defines for Jim */ 00003 // #define LONGNAMES 00004 #define SECPKG "[Tmpv1_0]" 00005 00006 #ifdef LONGNAMES 00007 #define SERVOP "DOMAIN_SERVER_OPERATORS " 00008 #define ACCTOP "DOMAIN_ACCOUNT_OPERATORS " 00009 #define COMMOP "DOMAIN_COMM_OPERATORS " 00010 #define PRINTOP "DOMAIN_PRINT_OPERATORS " 00011 #define DISKOP "DOMAIN_DISK_OPERATORS " 00012 #define AUDITOP "DOMAIN_AUDIT_OPERATORS " 00013 #define GADMINS "DOMAIN_ADMIN " 00014 #define GUSERS "DOMAIN_USERS " 00015 #define GGUESTS "DOMAIN_GUESTS " 00016 #else 00017 #define SERVOP "D_SERVER " 00018 #define ACCTOP "D_ACCOUN " 00019 #define COMMOP "D_COMM_O " 00020 #define PRINTOP "D_PRINT_ " 00021 #define DISKOP "D_DISK_O " 00022 #define AUDITOP "D_AUDIT_ " 00023 #define GADMINS "D_ADMIN " 00024 #define GUSERS "D_USERS " 00025 #define GGUESTS "D_GUESTS " 00026 #endif 00027 00028 00029 #define INCL_DOSMEMMGR 00030 #include <os2.h> 00031 #include <stdio.h> 00032 #include <string.h> 00033 #include <stdlib.h> 00034 #include <netcons.h> 00035 #include <neterr.h> 00036 #include <netlib.h> 00037 #include <uascache.h> 00038 #include <access.h> 00039 #include <permit.h> 00040 #include "ssitools.h" 00041 00042 char FAR * buf1; 00043 char FAR * buf2; 00044 char FAR * GroupCache; 00045 char path[256]; 00046 char userbuf[MAX_USER_SIZE]; 00047 unsigned short Handle; 00048 struct _ahdr FAR * Header; 00049 00050 void InitMemStuff(void); 00051 void loadit(void); 00052 void showentries(void); 00053 void doargs(int, char**); 00054 00055 struct my_group { 00056 char name[GNLEN + 1]; 00057 char pad; 00058 unsigned short gid; 00059 unsigned long serial; 00060 }; 00061 00062 static int 00063 UserHashVal(uname, domain) 00064 const char far *uname; 00065 int domain; 00066 { 00067 register unsigned val=0; 00068 register unsigned char c; 00069 00070 while ((c= (unsigned char) *uname++)) 00071 val += toupper(c); 00072 00073 return (int) (val % domain); 00074 } 00075 00076 unsigned 00077 dread(unsigned handle, unsigned long pos, char far * buffer, unsigned length) 00078 { 00079 unsigned short err, bread; 00080 unsigned long newpos; 00081 00082 err = DosChgFilePtr(handle, pos, FILE_BEGIN, &newpos); 00083 if (err) 00084 return err; 00085 if (newpos != pos) 00086 return NERR_ACFFileIOFail; 00087 err = DosRead( handle, buffer, length, &bread); 00088 if (err) 00089 return err; 00090 if (bread != length) 00091 return NERR_ACFFileIOFail; 00092 return 0; 00093 } 00094 00095 unsigned read_object(unsigned handle, unsigned long pos, char FAR * buf) 00096 { 00097 unsigned err; 00098 struct disk_obj_hdr FAR * dobj; 00099 00100 err = dread(handle, pos, buf, sizeof(struct disk_obj_hdr)); 00101 if (err) 00102 return err; 00103 dobj = (struct disk_obj_hdr FAR *) buf; 00104 return dread(handle, pos, buf, dobj->do_numblocks * 64); 00105 } 00106 00107 void InitMemStuff() 00108 { 00109 unsigned short err; 00110 unsigned short sel, action; 00111 00112 err = DosAllocSeg(0x8000, &sel, 0); 00113 if (err) { 00114 printf("Could not alloc memory, error %d\n", err); 00115 exit(1); 00116 } 00117 buf1 = MAKEP(sel, 0); 00118 err = DosAllocSeg(0x8000, &sel, 0); 00119 if (err) { 00120 printf("Could not alloc memory, error %d\n", err); 00121 exit(1); 00122 } 00123 buf2 = MAKEP(sel, 0); 00124 err = DosAllocSeg(1024, &sel, 0); 00125 if (err) { 00126 printf("Could not alloc memory, error %d\n", err); 00127 exit(1); 00128 } 00129 Header = MAKEP(sel, 0); 00130 if (err = DosAllocSeg(0x8000, &sel, 0)) { 00131 printf("Could not alloc memory, error %d\n", err); 00132 exit(1); 00133 } 00134 GroupCache = MAKEP(sel, 0); 00135 err = DosOpen(path, &Handle, &action, 0L, 0, FILE_OPEN, 00136 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, 0L); 00137 if (err) { 00138 printf("Error opening %s, code %d\n", path, err); 00139 exit(1); 00140 } 00141 err = DosRead(Handle, Header, 512, &action); 00142 if (err || action != 512) { 00143 printf("Error reading from file, code %d\n", err); 00144 exit(1); 00145 } 00146 printf("Total users, %d\n", Header->num_users); 00147 } 00148 00149 void loadit() 00150 { 00151 unsigned short err; 00152 unsigned short action; 00153 unsigned short i; 00154 unsigned long pos; 00155 struct diskuserhash FAR *diskhashentry; 00156 struct userhash FAR *userhashentry; 00157 struct _grouprec FAR * grec; 00158 struct my_group FAR * mygroup; 00159 00160 err = DosChgFilePtr(Handle, 512L, FILE_BEGIN, &pos); 00161 err = DosRead(Handle, buf1, sizeof(struct _grouprec) * MAXGROUP, &action); 00162 if (err || action != sizeof(struct _grouprec) * MAXGROUP) { 00163 printf("Error reading from file, %d\n", err); 00164 exit(1); 00165 } 00166 mygroup = (struct my_group FAR *) GroupCache; 00167 grec = (struct _grouprec FAR *) buf1; 00168 for (i = 0; i < MAXGROUP ; i++, grec++, mygroup++ ) { 00169 if (grec->name[0] != REC_EMPTY && grec->name[0] != REC_DELETE) { 00170 /* if (strcmpf(grec->name, "ADMINS") == 0) { 00171 strcpyf(mygroup->name, GADMIN); 00172 else if (strcmpf(grec->name, "USERS") == 0) 00173 strcpyf(mygroup->name, GUSERS); 00174 else if (strcmpf(grec->name, "GUESTS") == 0) 00175 strcpyf(mygroup->name, GGUESTS); 00176 else */ 00177 strncpyf(mygroup->name, grec->name, GNLEN); 00178 mygroup->gid = UserHashVal(mygroup->name, MAXGROUP); 00179 mygroup->serial = grec->serial; 00180 } else 00181 mygroup->name[0] = '\0'; 00182 } 00183 00184 err = DosChgFilePtr(Handle, (unsigned long) HASH_TBL_OFFSET, FILE_BEGIN, &pos); 00185 diskhashentry = (struct diskuserhash FAR *) buf1; 00186 if (err = DosRead (Handle, diskhashentry, HASH_TBL_SIZE, &action)) { 00187 printf("Could not read hash table, error %d\n", err); 00188 exit(1); 00189 } 00190 00191 if (action != HASH_TBL_SIZE) { 00192 printf("Could not read hash table\n"); 00193 exit(1); 00194 } 00195 /* 00196 * Copy disk user hash table into memory 00197 */ 00198 userhashentry = (struct userhash FAR *) buf2; 00199 for (i = 0; i < USER_HASH_ENTRIES; i++) { 00200 userhashentry->uh_disk = diskhashentry->dh_disk; 00201 userhashentry->uh_serial = diskhashentry->dh_serial; 00202 userhashentry->uh_cache = NULL; 00203 userhashentry++; 00204 diskhashentry++; 00205 } 00206 } 00207 00208 void printgroups() 00209 { 00210 struct my_group FAR * mygroup = (struct my_group FAR *) GroupCache; 00211 unsigned i; 00212 unsigned long relid; 00213 00214 printf("\t// Groups\n"); 00215 for (i = 0; i< MAXGROUP ; i++, mygroup++ ) { 00216 if (mygroup->name[0]) { 00217 relid = ((mygroup->gid | GROUPIDMASK) + (mygroup->serial << 16)) ^ 0x80000000L; 00218 printf("\tGroup = %ld %Fs\n", relid, mygroup->name); 00219 } 00220 } 00221 } 00222 void showentries() 00223 { 00224 unsigned i, j, k; 00225 unsigned err; 00226 unsigned long pos, oprights; 00227 signed long relativeid; 00228 unsigned usercount = 0; 00229 struct userhash FAR * entry = (struct userhash FAR *) buf2; 00230 struct user_object FAR * uo = (struct user_object FAR *) userbuf; 00231 struct my_group FAR * mygroup = (struct my_group FAR *) GroupCache; 00232 unsigned char FAR * gmask; 00233 unsigned char test; 00234 char groupnames[256]; 00235 00236 printf("\n\n\t// Users\n"); 00237 for (i = 0; i < USER_HASH_ENTRIES ; i++ ) { 00238 pos = entry->uh_disk; 00239 while (pos) { 00240 if (err = read_object(Handle, pos, userbuf)) { 00241 printf("Failed reading object, code %d\n", err); 00242 exit(1); 00243 } 00244 relativeid = ( ((uo->uo_record.user.uc0_guid.guid_serial) << 16) + 00245 (uo->uo_record.user.uc0_guid.guid_uid) ) ^ 0x80000000; 00246 gmask = uo->uo_record.user.uc0_groups; 00247 groupnames[0] = '\0'; 00248 for (j = 0; j < 32 ; j++ ) { 00249 test = gmask[j]; 00250 k = 0; 00251 while (test) { 00252 if (test & 1) { 00253 strcatf(groupnames, mygroup[j * 8 + k].name); 00254 strcatf(groupnames, " "); 00255 } 00256 test >>= 1; 00257 k++; 00258 } 00259 } 00260 00261 oprights = uo->uo_record.user.uc0_auth_flags; 00262 if (oprights & AF_OP_PRINT) 00263 strcat(groupnames, PRINTOP); 00264 if (oprights & AF_OP_COMM) 00265 strcat(groupnames, COMMOP); 00266 if (oprights & AF_OP_SERVER) 00267 strcat(groupnames, SERVOP); 00268 if (oprights & AF_OP_ACCOUNTS) 00269 strcat(groupnames, ACCTOP); 00270 00271 printf("\tUser = %ld %Fs %Fs\n", relativeid, 00272 (char FAR *) uo->uo_record.name, 00273 (char FAR *) groupnames); 00274 usercount++; 00275 pos = uo->uo_header.do_next; 00276 } 00277 entry++; 00278 } 00279 if (usercount != Header->num_users) { 00280 printf("Huh? Didn't find all the users (found %d)\n", usercount); 00281 } 00282 } 00283 00284 void banner(unsigned longnames) 00285 { 00286 00287 printf(SECPKG); 00288 printf("\n\n\t//\n\t// Account Setup information\n"); 00289 printf("\t// This file produced from the LAN Manager 2.0 UAS\n"); 00290 printf("\t// %s\n", path); 00291 00292 printf("\tGroup = 501 %s\n", GADMINS); 00293 printf("\tGroup = 502 %s\n", GUSERS); 00294 printf("\tGroup = 503 %s\n", GGUESTS); 00295 printf("\tGroup = 504 %s\n", ACCTOP); 00296 printf("\tGroup = 505 %s\n", SERVOP); 00297 printf("\tGroup = 506 %s\n", PRINTOP); 00298 printf("\tGroup = 507 %s\n", COMMOP); 00299 printf("\tGroup = 508 %s\n", DISKOP); 00300 printf("\tGroup = 509 %s\n", AUDITOP); 00301 } 00302 00303 void doargs(int argc, char **argv) 00304 { 00305 if (argc != 2 || *argv[1] == '?') { 00306 printf("usage: %s path\\net.acc\n", argv[0]); 00307 printf("\tlists all the users/groups and their hash/serial numbers for a UAS\n"); 00308 exit(0); 00309 } 00310 strcpy(path, argv[1]); 00311 } 00312 00313 main (int argc, char *argv[]) 00314 { 00315 printf(SIGNON); 00316 doargs(argc, argv); 00317 InitMemStuff(); 00318 loadit(); 00319 00320 banner(0); 00321 00322 printgroups(); 00323 showentries(); 00324 }

Generated on Sat May 15 19:39:47 2004 for test by doxygen 1.3.7