3 * This generates the user, list, list membership, filesys data
4 * for windows active directory update
6 * (c) Copyright 1988-2001 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
13 #include <moira_site.h>
22 EXEC SQL INCLUDE sqlca;
25 #define WINAD_SUBDIR "winad"
28 char winad_dir[MAXPATHLEN];
29 char *whoami = "winad.gen";
30 char *db = "moira/moira";
34 int do_groupmembership(void);
35 int do_containers(void);
37 int main(int argc, char **argv)
45 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
49 initialize_sms_error_table();
50 sprintf(winad_dir, "%s/%s", DCM_DIR, WINAD_SUBDIR);
55 changed += do_groups();
56 changed += do_groupmembership();
57 changed += do_containers();
61 fprintf(stderr, "No files updated.\n");
62 if (argc == 2 && stat(argv[1], &sb) == 0)
68 fprintf(stderr, "Building tar file.\n");
69 sprintf(cmd, "cd %s; tar cf %s .", winad_dir, argv[1]);
81 char foutf[MAXPATHLEN];
82 char foutft[MAXPATHLEN];
83 EXEC SQL BEGIN DECLARE SECTION;
84 char login[USERS_LOGIN_SIZE];
85 char mit_id[USERS_CLEARID_SIZE];
86 int users_id, unix_uid, status;
87 char type[FILESYS_TYPE_SIZE];
88 char name[FILESYS_NAME_SIZE];
89 char homedir[USERS_WINHOMEDIR_SIZE];
90 char profiledir[USERS_WINPROFILEDIR_SIZE];
92 EXEC SQL END DECLARE SECTION;
94 sprintf(foutf, "%s/winuser.db", winad_dir);
95 sprintf(foutft, "%s~", foutf);
97 fout = fopen(foutft, "w");
100 perror("cannot open winuser.db for write");
104 EXEC SQL DECLARE u_cursor CURSOR FOR
105 SELECT users_id, login, unix_uid, status, clearid, winhomedir,
109 EXEC SQL OPEN u_cursor;
112 EXEC SQL FETCH u_cursor INTO :users_id, :login, :unix_uid, :status,
113 :mit_id, :homedir, :profiledir;
121 if (strcmp(mit_id, "") == 0)
124 if (strcasecmp(homedir, "[AFS]") == 0 || strcasecmp(profiledir,
127 EXEC SQL SELECT filsys_id into :fid
129 WHERE lockertype = 'HOMEDIR'
131 AND type = 'FSGROUP';
133 if (sqlca.sqlcode == 0)
135 EXEC SQL DECLARE f_cursor CURSOR FOR
137 FROM filesys a, fsgroup b
138 WHERE a.filsys_id=b.filsys_id
142 EXEC SQL OPEN f_cursor;
144 EXEC SQL FETCH f_cursor INTO :type, :name;
146 if (sqlca.sqlcode == 0)
153 strcpy(type, "NONE");
154 strcpy(name, "NONE");
157 EXEC SQL CLOSE f_cursor;
162 EXEC SQL SELECT type, name into :type, :name
164 WHERE lockertype = 'HOMEDIR'
167 if (sqlca.sqlcode == 0)
174 strcpy(type, "NONE");
175 strcpy(name, "NONE");
178 if (strcasecmp(type, "AFS") != 0)
179 strcpy(name, "[LOCAL]");
183 if (strcasecmp(homedir, "[AFS]") == 0)
184 strcpy(homedir, name);
186 if (strcasecmp(profiledir, "[AFS]") == 0)
188 strcpy(profiledir, name);
189 if (strcasecmp(name, "[LOCAL]"))
190 strcat(profiledir, "/.winprofile");
193 fprintf(fout, "%d %s %d %d %s %s %s\n",
194 users_id, login, unix_uid, status, mit_id,
195 homedir, profiledir);
198 if (sqlca.sqlcode < 0)
199 db_error(sqlca.sqlcode);
200 EXEC SQL CLOSE u_cursor;
205 fprintf(stderr, "Unsuccessful file close of winuser.db\n");
217 char foutf[MAXPATHLEN];
218 char foutft[MAXPATHLEN];
219 EXEC SQL BEGIN DECLARE SECTION;
220 char listname[LIST_NAME_SIZE];
221 char description[LIST_DESCRIPTION_SIZE];
222 char acltype[LIST_ACL_TYPE_SIZE];
224 char aclname[STRINGS_STRING_SIZE];
225 int list_id, active, publicflg, hidden, maillist, grouplist;
226 EXEC SQL END DECLARE SECTION;
228 sprintf(foutf, "%s/wingroup.db", winad_dir);
229 sprintf(foutft, "%s~", foutf);
231 fout = fopen(foutft, "w");
234 perror("cannot open wingroup.db for write");
238 EXEC SQL DECLARE l_cursor CURSOR FOR
239 SELECT list_id, name, active, publicflg, hidden, maillist,
240 grouplist, description, acl_type, acl_id
243 EXEC SQL OPEN l_cursor;
246 EXEC SQL FETCH l_cursor INTO :list_id, :listname, :active, :publicflg,
247 :hidden, :maillist, :grouplist, :description, :acltype, :aclid;
253 strtrim(description);
257 strcpy(aclname, "NONE");
258 if (strcmp(acltype, "LIST") == 0)
260 EXEC SQL SELECT name into :aclname
262 WHERE list_id = :aclid;
264 else if (strcmp(acltype, "USER") == 0)
266 EXEC SQL SELECT login into :aclname
268 WHERE users_id = :aclid;
270 else if (strcmp(acltype, "KERBEROS") == 0)
272 EXEC SQL SELECT string into :aclname
274 WHERE string_id = :aclid;
279 fprintf(fout, "%d %s %d %d %d %d %d %s %s %s\n",
280 list_id, listname, active, publicflg, hidden, maillist,
281 grouplist, acltype, aclname, description);
284 if (sqlca.sqlcode < 0)
285 db_error(sqlca.sqlcode);
286 EXEC SQL CLOSE l_cursor;
291 fprintf(stderr, "Unsuccessful file close of wingroup.db\n");
299 int do_groupmembership(void)
302 char foutf[MAXPATHLEN];
303 char foutft[MAXPATHLEN];
304 EXEC SQL BEGIN DECLARE SECTION;
305 char member_type[IMEMBERS_MEMBER_TYPE_SIZE];
306 char member_name[STRINGS_STRING_SIZE];
308 EXEC SQL END DECLARE SECTION;
310 sprintf(foutf, "%s/wingmember.db", winad_dir);
311 sprintf(foutft, "%s~", foutf);
313 fout = fopen(foutft, "w");
316 perror("cannot open wingmember.db for write");
320 EXEC SQL DECLARE list_cursor CURSOR FOR
325 EXEC SQL OPEN list_cursor;
328 EXEC SQL FETCH list_cursor INTO :list_id;
333 /* get all the users */
334 EXEC SQL DECLARE csr001 CURSOR FOR
335 SELECT i.member_type, u.login
336 FROM users u, imembers i
337 WHERE i.list_id = :list_id AND i.member_type = 'USER'
338 AND i.member_id = u.users_id
341 EXEC SQL OPEN csr001;
344 EXEC SQL FETCH csr001 into :member_type, :member_name;
347 fprintf(fout, "%d %s %s\n",
348 list_id, member_type, member_name);
351 if (sqlca.sqlcode < 0)
352 db_error(sqlca.sqlcode);
353 EXEC SQL CLOSE csr001;
355 /* get all the KERBEROS AND STRINGS */
356 EXEC SQL DECLARE csr002 CURSOR FOR
357 SELECT i.member_type, s.string
358 FROM strings s, imembers i
359 WHERE i.list_id = :list_id AND
360 (i.member_type = 'KERBEROS' OR i.member_type = 'STRING')
361 AND i.member_id = s.string_id
364 EXEC SQL OPEN csr002;
367 EXEC SQL FETCH csr002 into :member_type, :member_name;
370 fprintf(fout, "%d %s %s\n",
371 list_id, member_type, member_name);
374 if (sqlca.sqlcode < 0)
375 db_error(sqlca.sqlcode);
377 EXEC SQL CLOSE csr002;
379 /* get all the machines */
380 EXEC SQL DECLARE csr003 CURSOR FOR
381 SELECT i.member_type, m.name
382 FROM machine m, imembers i
383 WHERE i.list_id = :list_id AND i.member_type = 'MACHINE'
384 AND i.member_id = m.mach_id
387 EXEC SQL OPEN csr003;
390 EXEC SQL FETCH csr003 into :member_type, :member_name;
393 fprintf(fout, "%d %s %s\n", list_id, member_type, member_name);
396 if (sqlca.sqlcode < 0)
397 db_error(sqlca.sqlcode);
398 EXEC SQL CLOSE csr003;
401 if (sqlca.sqlcode < 0)
402 db_error(sqlca.sqlcode);
404 EXEC SQL CLOSE list_cursor;
409 fprintf(stderr, "Unsuccessful file close of wingmember.db\n");
417 int do_containers(void)
420 char foutf[MAXPATHLEN];
421 char foutft[MAXPATHLEN];
422 EXEC SQL BEGIN DECLARE SECTION;
423 char container_name[CONTAINERS_NAME_SIZE];
424 char acl_type[CONTAINERS_ACL_TYPE_SIZE];
425 char acl_name[STRINGS_STRING_SIZE];
426 char description[CONTAINERS_DESCRIPTION_SIZE];
429 EXEC SQL END DECLARE SECTION;
431 sprintf(foutf, "%s/wincontainer.db", winad_dir);
432 sprintf(foutft, "%s~", foutf);
434 fout = fopen(foutft, "w");
437 perror("cannot open wincontainer.db for write");
441 EXEC SQL DECLARE container_cursor CURSOR FOR
442 SELECT name, cnt_id, acl_type, acl_id, description
444 ORDER BY cnt_id, name;
445 EXEC SQL OPEN container_cursor;
448 EXEC SQL FETCH container_cursor INTO :container_name, :cnt_id,
449 :acl_type, :acl_id, :description ;
454 strtrim(container_name);
456 strtrim(description);
458 strcpy(acl_name, "NONE");
459 if (strcmp(acl_type, "LIST") == 0)
461 EXEC SQL SELECT name into :acl_name
463 WHERE list_id = :acl_id;
465 else if (strcmp(acl_type, "USER") == 0)
467 EXEC SQL SELECT login into :acl_name
469 WHERE users_id = :acl_id;
471 else if (strcmp(acl_type, "KERBEROS") == 0)
473 EXEC SQL SELECT string into :acl_name
475 WHERE string_id = :acl_id;
480 fprintf(fout, "%d,%s,%s,%s,%s\n",
481 cnt_id, container_name, acl_type, acl_name,
484 if (sqlca.sqlcode < 0)
485 db_error(sqlca.sqlcode);
487 EXEC SQL CLOSE container_cursor;
492 fprintf(stderr, "Unsuccessful file close of wincontainer.db\n");