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, 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, maillist, grouplist, description,
243 EXEC SQL OPEN l_cursor;
246 EXEC SQL FETCH l_cursor INTO :list_id, :listname, :active, :maillist,
248 :description, :acltype, :aclid;
254 strtrim(description);
258 strcpy(aclname, "NONE");
259 if (strcmp(acltype, "LIST") == 0)
261 EXEC SQL SELECT name into :aclname
263 WHERE list_id = :aclid;
265 else if (strcmp(acltype, "USER") == 0)
267 EXEC SQL SELECT login into :aclname
269 WHERE users_id = :aclid;
271 else if (strcmp(acltype, "KERBEROS") == 0)
273 EXEC SQL SELECT string into :aclname
275 WHERE string_id = :aclid;
280 fprintf(fout, "%d %s %d %d %d %s %s %s\n",
281 list_id, listname, active, maillist, grouplist, acltype, aclname,
285 if (sqlca.sqlcode < 0)
286 db_error(sqlca.sqlcode);
287 EXEC SQL CLOSE l_cursor;
292 fprintf(stderr, "Unsuccessful file close of wingroup.db\n");
300 int do_groupmembership(void)
303 char foutf[MAXPATHLEN];
304 char foutft[MAXPATHLEN];
305 EXEC SQL BEGIN DECLARE SECTION;
306 char member_type[IMEMBERS_MEMBER_TYPE_SIZE];
307 char member_name[STRINGS_STRING_SIZE];
309 EXEC SQL END DECLARE SECTION;
311 sprintf(foutf, "%s/wingmember.db", winad_dir);
312 sprintf(foutft, "%s~", foutf);
314 fout = fopen(foutft, "w");
317 perror("cannot open wingmember.db for write");
321 EXEC SQL DECLARE list_cursor CURSOR FOR
326 EXEC SQL OPEN list_cursor;
329 EXEC SQL FETCH list_cursor INTO :list_id;
334 /* get all the users */
335 EXEC SQL DECLARE csr001 CURSOR FOR
336 SELECT i.member_type, u.login
337 FROM users u, imembers i
338 WHERE i.list_id = :list_id AND i.member_type = 'USER'
339 AND i.member_id = u.users_id
342 EXEC SQL OPEN csr001;
345 EXEC SQL FETCH csr001 into :member_type, :member_name;
348 fprintf(fout, "%d %s %s\n",
349 list_id, member_type, member_name);
352 if (sqlca.sqlcode < 0)
353 db_error(sqlca.sqlcode);
354 EXEC SQL CLOSE csr001;
356 /* get all the KERBEROS AND STRINGS */
357 EXEC SQL DECLARE csr002 CURSOR FOR
358 SELECT i.member_type, s.string
359 FROM strings s, imembers i
360 WHERE i.list_id = :list_id AND
361 (i.member_type = 'KERBEROS' OR i.member_type = 'STRING')
362 AND i.member_id = s.string_id
365 EXEC SQL OPEN csr002;
368 EXEC SQL FETCH csr002 into :member_type, :member_name;
371 fprintf(fout, "%d %s %s\n",
372 list_id, member_type, member_name);
375 if (sqlca.sqlcode < 0)
376 db_error(sqlca.sqlcode);
378 EXEC SQL CLOSE csr002;
381 if (sqlca.sqlcode < 0)
382 db_error(sqlca.sqlcode);
384 EXEC SQL CLOSE list_cursor;
389 fprintf(stderr, "Unsuccessful file close of wingmember.db\n");
397 int do_containers(void)
400 char foutf[MAXPATHLEN];
401 char foutft[MAXPATHLEN];
402 EXEC SQL BEGIN DECLARE SECTION;
403 char container_name[CONTAINERS_NAME_SIZE];
404 char acl_type[CONTAINERS_ACL_TYPE_SIZE];
405 char acl_name[STRINGS_STRING_SIZE];
406 char description[CONTAINERS_DESCRIPTION_SIZE];
409 EXEC SQL END DECLARE SECTION;
411 sprintf(foutf, "%s/wincontainer.db", winad_dir);
412 sprintf(foutft, "%s~", foutf);
414 fout = fopen(foutft, "w");
417 perror("cannot open wincontainer.db for write");
421 EXEC SQL DECLARE container_cursor CURSOR FOR
422 SELECT name, cnt_id, acl_type, acl_id, description
424 ORDER BY cnt_id, name;
425 EXEC SQL OPEN container_cursor;
428 EXEC SQL FETCH container_cursor INTO :container_name, :cnt_id,
429 :acl_type, :acl_id, :description ;
434 strtrim(container_name);
436 strtrim(description);
438 strcpy(acl_name, "NONE");
439 if (strcmp(acl_type, "LIST") == 0)
441 EXEC SQL SELECT name into :acl_name
443 WHERE list_id = :acl_id;
445 else if (strcmp(acl_type, "USER") == 0)
447 EXEC SQL SELECT login into :acl_name
449 WHERE users_id = :acl_id;
451 else if (strcmp(acl_type, "KERBEROS") == 0)
453 EXEC SQL SELECT string into :acl_name
455 WHERE string_id = :acl_id;
460 fprintf(fout, "%d,%s,%s,%s,%s\n",
461 cnt_id, container_name, acl_type, acl_name,
464 if (sqlca.sqlcode < 0)
465 db_error(sqlca.sqlcode);
467 EXEC SQL CLOSE container_cursor;
472 fprintf(stderr, "Unsuccessful file close of wincontainer.db\n");