Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

324 lines
9.1 KiB

  1. /* Defines for Jim */
  2. // #define LONGNAMES
  3. #define SECPKG "[Tmpv1_0]"
  4. #ifdef LONGNAMES
  5. #define SERVOP "DOMAIN_SERVER_OPERATORS "
  6. #define ACCTOP "DOMAIN_ACCOUNT_OPERATORS "
  7. #define COMMOP "DOMAIN_COMM_OPERATORS "
  8. #define PRINTOP "DOMAIN_PRINT_OPERATORS "
  9. #define DISKOP "DOMAIN_DISK_OPERATORS "
  10. #define AUDITOP "DOMAIN_AUDIT_OPERATORS "
  11. #define GADMINS "DOMAIN_ADMIN "
  12. #define GUSERS "DOMAIN_USERS "
  13. #define GGUESTS "DOMAIN_GUESTS "
  14. #else
  15. #define SERVOP "D_SERVER "
  16. #define ACCTOP "D_ACCOUN "
  17. #define COMMOP "D_COMM_O "
  18. #define PRINTOP "D_PRINT_ "
  19. #define DISKOP "D_DISK_O "
  20. #define AUDITOP "D_AUDIT_ "
  21. #define GADMINS "D_ADMIN "
  22. #define GUSERS "D_USERS "
  23. #define GGUESTS "D_GUESTS "
  24. #endif
  25. #define INCL_DOSMEMMGR
  26. #include <os2.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <netcons.h>
  31. #include <neterr.h>
  32. #include <netlib.h>
  33. #include <uascache.h>
  34. #include <access.h>
  35. #include <permit.h>
  36. #include "ssitools.h"
  37. char FAR * buf1;
  38. char FAR * buf2;
  39. char FAR * GroupCache;
  40. char path[256];
  41. char userbuf[MAX_USER_SIZE];
  42. unsigned short Handle;
  43. struct _ahdr FAR * Header;
  44. void InitMemStuff(void);
  45. void loadit(void);
  46. void showentries(void);
  47. void doargs(int, char**);
  48. struct my_group {
  49. char name[GNLEN + 1];
  50. char pad;
  51. unsigned short gid;
  52. unsigned long serial;
  53. };
  54. static int
  55. UserHashVal(uname, domain)
  56. const char far *uname;
  57. int domain;
  58. {
  59. register unsigned val=0;
  60. register unsigned char c;
  61. while ((c= (unsigned char) *uname++))
  62. val += toupper(c);
  63. return (int) (val % domain);
  64. }
  65. unsigned
  66. dread(unsigned handle, unsigned long pos, char far * buffer, unsigned length)
  67. {
  68. unsigned short err, bread;
  69. unsigned long newpos;
  70. err = DosChgFilePtr(handle, pos, FILE_BEGIN, &newpos);
  71. if (err)
  72. return err;
  73. if (newpos != pos)
  74. return NERR_ACFFileIOFail;
  75. err = DosRead( handle, buffer, length, &bread);
  76. if (err)
  77. return err;
  78. if (bread != length)
  79. return NERR_ACFFileIOFail;
  80. return 0;
  81. }
  82. unsigned read_object(unsigned handle, unsigned long pos, char FAR * buf)
  83. {
  84. unsigned err;
  85. struct disk_obj_hdr FAR * dobj;
  86. err = dread(handle, pos, buf, sizeof(struct disk_obj_hdr));
  87. if (err)
  88. return err;
  89. dobj = (struct disk_obj_hdr FAR *) buf;
  90. return dread(handle, pos, buf, dobj->do_numblocks * 64);
  91. }
  92. void InitMemStuff()
  93. {
  94. unsigned short err;
  95. unsigned short sel, action;
  96. err = DosAllocSeg(0x8000, &sel, 0);
  97. if (err) {
  98. printf("Could not alloc memory, error %d\n", err);
  99. exit(1);
  100. }
  101. buf1 = MAKEP(sel, 0);
  102. err = DosAllocSeg(0x8000, &sel, 0);
  103. if (err) {
  104. printf("Could not alloc memory, error %d\n", err);
  105. exit(1);
  106. }
  107. buf2 = MAKEP(sel, 0);
  108. err = DosAllocSeg(1024, &sel, 0);
  109. if (err) {
  110. printf("Could not alloc memory, error %d\n", err);
  111. exit(1);
  112. }
  113. Header = MAKEP(sel, 0);
  114. if (err = DosAllocSeg(0x8000, &sel, 0)) {
  115. printf("Could not alloc memory, error %d\n", err);
  116. exit(1);
  117. }
  118. GroupCache = MAKEP(sel, 0);
  119. err = DosOpen(path, &Handle, &action, 0L, 0, FILE_OPEN,
  120. OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, 0L);
  121. if (err) {
  122. printf("Error opening %s, code %d\n", path, err);
  123. exit(1);
  124. }
  125. err = DosRead(Handle, Header, 512, &action);
  126. if (err || action != 512) {
  127. printf("Error reading from file, code %d\n", err);
  128. exit(1);
  129. }
  130. printf("Total users, %d\n", Header->num_users);
  131. }
  132. void loadit()
  133. {
  134. unsigned short err;
  135. unsigned short action;
  136. unsigned short i;
  137. unsigned long pos;
  138. struct diskuserhash FAR *diskhashentry;
  139. struct userhash FAR *userhashentry;
  140. struct _grouprec FAR * grec;
  141. struct my_group FAR * mygroup;
  142. err = DosChgFilePtr(Handle, 512L, FILE_BEGIN, &pos);
  143. err = DosRead(Handle, buf1, sizeof(struct _grouprec) * MAXGROUP, &action);
  144. if (err || action != sizeof(struct _grouprec) * MAXGROUP) {
  145. printf("Error reading from file, %d\n", err);
  146. exit(1);
  147. }
  148. mygroup = (struct my_group FAR *) GroupCache;
  149. grec = (struct _grouprec FAR *) buf1;
  150. for (i = 0; i < MAXGROUP ; i++, grec++, mygroup++ ) {
  151. if (grec->name[0] != REC_EMPTY && grec->name[0] != REC_DELETE) {
  152. /* if (strcmpf(grec->name, "ADMINS") == 0) {
  153. strcpyf(mygroup->name, GADMIN);
  154. else if (strcmpf(grec->name, "USERS") == 0)
  155. strcpyf(mygroup->name, GUSERS);
  156. else if (strcmpf(grec->name, "GUESTS") == 0)
  157. strcpyf(mygroup->name, GGUESTS);
  158. else */
  159. strncpyf(mygroup->name, grec->name, GNLEN);
  160. mygroup->gid = UserHashVal(mygroup->name, MAXGROUP);
  161. mygroup->serial = grec->serial;
  162. } else
  163. mygroup->name[0] = '\0';
  164. }
  165. err = DosChgFilePtr(Handle, (unsigned long) HASH_TBL_OFFSET, FILE_BEGIN, &pos);
  166. diskhashentry = (struct diskuserhash FAR *) buf1;
  167. if (err = DosRead (Handle, diskhashentry, HASH_TBL_SIZE, &action)) {
  168. printf("Could not read hash table, error %d\n", err);
  169. exit(1);
  170. }
  171. if (action != HASH_TBL_SIZE) {
  172. printf("Could not read hash table\n");
  173. exit(1);
  174. }
  175. /*
  176. * Copy disk user hash table into memory
  177. */
  178. userhashentry = (struct userhash FAR *) buf2;
  179. for (i = 0; i < USER_HASH_ENTRIES; i++) {
  180. userhashentry->uh_disk = diskhashentry->dh_disk;
  181. userhashentry->uh_serial = diskhashentry->dh_serial;
  182. userhashentry->uh_cache = NULL;
  183. userhashentry++;
  184. diskhashentry++;
  185. }
  186. }
  187. void printgroups()
  188. {
  189. struct my_group FAR * mygroup = (struct my_group FAR *) GroupCache;
  190. unsigned i;
  191. unsigned long relid;
  192. printf("\t// Groups\n");
  193. for (i = 0; i< MAXGROUP ; i++, mygroup++ ) {
  194. if (mygroup->name[0]) {
  195. relid = ((mygroup->gid | GROUPIDMASK) + (mygroup->serial << 16)) ^ 0x80000000L;
  196. printf("\tGroup = %ld %Fs\n", relid, mygroup->name);
  197. }
  198. }
  199. }
  200. void showentries()
  201. {
  202. unsigned i, j, k;
  203. unsigned err;
  204. unsigned long pos, oprights;
  205. signed long relativeid;
  206. unsigned usercount = 0;
  207. struct userhash FAR * entry = (struct userhash FAR *) buf2;
  208. struct user_object FAR * uo = (struct user_object FAR *) userbuf;
  209. struct my_group FAR * mygroup = (struct my_group FAR *) GroupCache;
  210. unsigned char FAR * gmask;
  211. unsigned char test;
  212. char groupnames[256];
  213. printf("\n\n\t// Users\n");
  214. for (i = 0; i < USER_HASH_ENTRIES ; i++ ) {
  215. pos = entry->uh_disk;
  216. while (pos) {
  217. if (err = read_object(Handle, pos, userbuf)) {
  218. printf("Failed reading object, code %d\n", err);
  219. exit(1);
  220. }
  221. relativeid = ( ((uo->uo_record.user.uc0_guid.guid_serial) << 16) +
  222. (uo->uo_record.user.uc0_guid.guid_uid) ) ^ 0x80000000;
  223. gmask = uo->uo_record.user.uc0_groups;
  224. groupnames[0] = '\0';
  225. for (j = 0; j < 32 ; j++ ) {
  226. test = gmask[j];
  227. k = 0;
  228. while (test) {
  229. if (test & 1) {
  230. strcatf(groupnames, mygroup[j * 8 + k].name);
  231. strcatf(groupnames, " ");
  232. }
  233. test >>= 1;
  234. k++;
  235. }
  236. }
  237. oprights = uo->uo_record.user.uc0_auth_flags;
  238. if (oprights & AF_OP_PRINT)
  239. strcat(groupnames, PRINTOP);
  240. if (oprights & AF_OP_COMM)
  241. strcat(groupnames, COMMOP);
  242. if (oprights & AF_OP_SERVER)
  243. strcat(groupnames, SERVOP);
  244. if (oprights & AF_OP_ACCOUNTS)
  245. strcat(groupnames, ACCTOP);
  246. printf("\tUser = %ld %Fs %Fs\n", relativeid,
  247. (char FAR *) uo->uo_record.name,
  248. (char FAR *) groupnames);
  249. usercount++;
  250. pos = uo->uo_header.do_next;
  251. }
  252. entry++;
  253. }
  254. if (usercount != Header->num_users) {
  255. printf("Huh? Didn't find all the users (found %d)\n", usercount);
  256. }
  257. }
  258. void banner(unsigned longnames)
  259. {
  260. printf(SECPKG);
  261. printf("\n\n\t//\n\t// Account Setup information\n");
  262. printf("\t// This file produced from the LAN Manager 2.0 UAS\n");
  263. printf("\t// %s\n", path);
  264. printf("\tGroup = 501 %s\n", GADMINS);
  265. printf("\tGroup = 502 %s\n", GUSERS);
  266. printf("\tGroup = 503 %s\n", GGUESTS);
  267. printf("\tGroup = 504 %s\n", ACCTOP);
  268. printf("\tGroup = 505 %s\n", SERVOP);
  269. printf("\tGroup = 506 %s\n", PRINTOP);
  270. printf("\tGroup = 507 %s\n", COMMOP);
  271. printf("\tGroup = 508 %s\n", DISKOP);
  272. printf("\tGroup = 509 %s\n", AUDITOP);
  273. }
  274. void doargs(int argc, char **argv)
  275. {
  276. if (argc != 2 || *argv[1] == '?') {
  277. printf("usage: %s path\\net.acc\n", argv[0]);
  278. printf("\tlists all the users/groups and their hash/serial numbers for a UAS\n");
  279. exit(0);
  280. }
  281. strcpy(path, argv[1]);
  282. }
  283. main (int argc, char *argv[])
  284. {
  285. printf(SIGNON);
  286. doargs(argc, argv);
  287. InitMemStuff();
  288. loadit();
  289. banner(0);
  290. printgroups();
  291. showentries();
  292. }