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);
36 int main(int argc, char **argv)
44 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
48 initialize_sms_error_table();
49 sprintf(winad_dir, "%s/%s", DCM_DIR, WINAD_SUBDIR);
54 changed += do_groups();
55 changed += do_groupmembership();
59 fprintf(stderr, "No files updated.\n");
60 if (argc == 2 && stat(argv[1], &sb) == 0)
66 fprintf(stderr, "Building tar file.\n");
67 sprintf(cmd, "cd %s; tar cf %s .", winad_dir, argv[1]);
79 char foutf[MAXPATHLEN];
80 char foutft[MAXPATHLEN];
81 EXEC SQL BEGIN DECLARE SECTION;
82 char login[USERS_LOGIN_SIZE];
83 char mit_id[USERS_CLEARID_SIZE];
84 int users_id, unix_uid, status;
85 char type[FILESYS_TYPE_SIZE];
86 char name[FILESYS_NAME_SIZE];
87 EXEC SQL END DECLARE SECTION;
89 sprintf(foutf, "%s/winuser.db", winad_dir);
90 sprintf(foutft, "%s~", foutf);
92 fout = fopen(foutft, "w");
95 perror("cannot open winuser.db for write");
99 EXEC SQL DECLARE u_cursor CURSOR FOR
100 SELECT users_id, login, unix_uid, status, clearid
103 EXEC SQL OPEN u_cursor;
106 EXEC SQL FETCH u_cursor INTO :users_id, :login, :unix_uid, :status,
113 EXEC SQL SELECT type, name INTO :type, :name
115 WHERE lockertype = 'HOMEDIR'
116 AND owner = :users_id;
118 if (sqlca.sqlcode == 0)
128 fprintf(fout, "%d %s %d %d %s %s %s\n",
129 users_id, login, unix_uid, status, mit_id,
133 if (sqlca.sqlcode < 0)
134 db_error(sqlca.sqlcode);
135 EXEC SQL CLOSE u_cursor;
140 fprintf(stderr, "Unsuccessful file close of winuser.db\n");
152 char foutf[MAXPATHLEN];
153 char foutft[MAXPATHLEN];
154 EXEC SQL BEGIN DECLARE SECTION;
155 char listname[LIST_NAME_SIZE];
156 char description[LIST_DESCRIPTION_SIZE];
157 char acltype[LIST_ACL_TYPE_SIZE];
159 char aclname[STRINGS_STRING_SIZE];
160 int list_id, active, maillist, grouplist;
161 EXEC SQL END DECLARE SECTION;
163 sprintf(foutf, "%s/wingroup.db", winad_dir);
164 sprintf(foutft, "%s~", foutf);
166 fout = fopen(foutft, "w");
169 perror("cannot open wingroup.db for write");
173 EXEC SQL DECLARE l_cursor CURSOR FOR
174 SELECT list_id, name, active, maillist, grouplist, description,
178 EXEC SQL OPEN l_cursor;
181 EXEC SQL FETCH l_cursor INTO :list_id, :listname, :active, :maillist,
183 :description, :acltype, :aclid;
189 strtrim(description);
194 if (strcmp(acltype, "LIST") == 0)
196 EXEC SQL SELECT name into :aclname
198 WHERE list_id = :aclid;
200 else if (strcmp(acltype, "USER") == 0)
202 EXEC SQL SELECT login into :aclname
204 WHERE users_id = :aclid;
206 else if (strcmp(acltype, "KERBEROS") == 0)
208 EXEC SQL SELECT string into :aclname
210 WHERE string_id = :aclid;
215 fprintf(fout, "%d %s %d %d %d %s %s %s\n",
216 list_id, listname, active, maillist, grouplist, acltype, aclname,
220 if (sqlca.sqlcode < 0)
221 db_error(sqlca.sqlcode);
222 EXEC SQL CLOSE l_cursor;
227 fprintf(stderr, "Unsuccessful file close of wingroup.db\n");
235 int do_groupmembership(void)
238 char foutf[MAXPATHLEN];
239 char foutft[MAXPATHLEN];
240 EXEC SQL BEGIN DECLARE SECTION;
241 char member_type[IMEMBERS_MEMBER_TYPE_SIZE];
242 char member_name[STRINGS_STRING_SIZE];
244 EXEC SQL END DECLARE SECTION;
246 sprintf(foutf, "%s/wingmember.db", winad_dir);
247 sprintf(foutft, "%s~", foutf);
249 fout = fopen(foutft, "w");
252 perror("cannot open wingmember.db for write");
256 EXEC SQL DECLARE list_cursor CURSOR FOR
261 EXEC SQL OPEN list_cursor;
264 EXEC SQL FETCH list_cursor INTO :list_id;
269 /* get all the users */
270 EXEC SQL DECLARE csr001 CURSOR FOR
271 SELECT i.member_type, u.login
272 FROM users u, imembers i
273 WHERE i.list_id = :list_id AND i.member_type = 'USER'
274 AND i.member_id = u.users_id
277 EXEC SQL OPEN csr001;
280 EXEC SQL FETCH csr001 into :member_type, :member_name;
283 fprintf(fout, "%d %s %s\n",
284 list_id, member_type, member_name);
287 if (sqlca.sqlcode < 0)
288 db_error(sqlca.sqlcode);
289 EXEC SQL CLOSE csr001;
291 /* get all the KERBEROS AND STRINGS */
292 EXEC SQL DECLARE csr002 CURSOR FOR
293 SELECT i.member_type, s.string
294 FROM strings s, imembers i
295 WHERE i.list_id = :list_id AND
296 (i.member_type = 'KERBEROS' OR i.member_type = 'STRING')
297 AND i.member_id = s.string_id
300 EXEC SQL OPEN csr002;
303 EXEC SQL FETCH csr002 into :member_type, :member_name;
306 fprintf(fout, "%d %s %s\n",
307 list_id, member_type, member_name);
310 if (sqlca.sqlcode < 0)
311 db_error(sqlca.sqlcode);
313 EXEC SQL CLOSE csr002;
316 if (sqlca.sqlcode < 0)
317 db_error(sqlca.sqlcode);
319 EXEC SQL CLOSE list_cursor;
324 fprintf(stderr, "Unsuccessful file close of wingmember.db\n");