]>
Commit | Line | Data |
---|---|---|
fb8809f4 | 1 | /* $Header$ |
2 | * | |
3 | * Do AFS incremental updates | |
4 | * | |
5 | * Copyright (C) 1989 by the Massachusetts Institute of Technology | |
6 | * for copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
8 | */ | |
9 | ||
10 | #include <sms.h> | |
11 | #include <sms_app.h> | |
f633445d | 12 | #include <sys/file.h> |
13 | ||
14 | #define file_exists(file) (access((file), F_OK) == 0) | |
fb8809f4 | 15 | |
a6be2cf4 | 16 | char prs[64], fs[64]; |
fb8809f4 | 17 | |
18 | char *whoami; | |
19 | ||
20 | main(argc, argv) | |
21 | char **argv; | |
22 | int argc; | |
23 | { | |
a7fdf2de | 24 | int beforec, afterc, i; |
fb8809f4 | 25 | char *table, **before, **after; |
810d12a7 | 26 | #ifdef DEBUG |
27 | char buf[1024]; | |
810d12a7 | 28 | #endif |
fb8809f4 | 29 | |
a7fdf2de | 30 | for (i = getdtablesize() - 1; i > 2; i--) |
31 | close(i); | |
32 | ||
fb8809f4 | 33 | table = argv[1]; |
34 | beforec = atoi(argv[2]); | |
35 | before = &argv[4]; | |
36 | afterc = atoi(argv[3]); | |
37 | after = &argv[4 + beforec]; | |
38 | whoami = argv[0]; | |
39 | ||
810d12a7 | 40 | #ifdef DEBUG |
41 | sprintf(buf, "%s (", table); | |
42 | for (i = 0; i < beforec; i++) { | |
43 | if (i > 0) | |
44 | strcat(buf, ","); | |
45 | strcat(buf, before[i]); | |
46 | } | |
47 | strcat(buf, ")->("); | |
48 | for (i = 0; i < afterc; i++) { | |
49 | if (i > 0) | |
50 | strcat(buf, ","); | |
51 | strcat(buf, after[i]); | |
52 | } | |
53 | strcat(buf, ")\n"); | |
54 | write(1,buf,strlen(buf)); | |
55 | #endif | |
56 | ||
fb8809f4 | 57 | initialize_sms_error_table(); |
58 | initialize_krb_error_table(); | |
a6be2cf4 | 59 | sprintf(prs, "%s/prs", BIN_DIR); |
60 | sprintf(fs, "%s/fs", BIN_DIR); | |
fb8809f4 | 61 | |
62 | if (!strcmp(table, "users")) { | |
63 | do_user(before, beforec, after, afterc); | |
64 | } else if (!strcmp(table, "list")) { | |
65 | do_list(before, beforec, after, afterc); | |
66 | } else if (!strcmp(table, "members")) { | |
67 | do_member(before, beforec, after, afterc); | |
68 | } else if (!strcmp(table, "filesys")) { | |
69 | do_filesys(before, beforec, after, afterc); | |
70 | } else if (!strcmp(table, "nfsquota")) { | |
71 | do_quota(before, beforec, after, afterc); | |
72 | } | |
fb8809f4 | 73 | exit(0); |
74 | } | |
75 | ||
76 | ||
77 | do_cmd(cmd) | |
78 | char *cmd; | |
79 | { | |
a7fdf2de | 80 | int success = 0, tries = 0; |
fb8809f4 | 81 | |
82 | while (success == 0 && tries < 3) { | |
a7fdf2de | 83 | com_err(whoami, 0, "Executing command: %s", cmd); |
84 | if (system(cmd) == 0) | |
85 | success++; | |
fb8809f4 | 86 | if (!success) { |
87 | tries++; | |
88 | sleep(5 * 60); | |
89 | } | |
90 | } | |
91 | if (!success) | |
92 | critical_alert("incremental", "failed command: %s", cmd); | |
93 | } | |
94 | ||
95 | ||
96 | do_user(before, beforec, after, afterc) | |
97 | char **before; | |
98 | int beforec; | |
99 | char **after; | |
100 | int afterc; | |
101 | { | |
102 | int bstate, astate; | |
103 | char cmd[512]; | |
104 | ||
105 | cmd[0] = bstate = astate = 0; | |
106 | if (afterc > U_STATE) | |
107 | astate = atoi(after[U_STATE]); | |
108 | if (beforec > U_STATE) | |
109 | bstate = atoi(before[U_STATE]); | |
810d12a7 | 110 | if (astate == 2) astate = 1; |
111 | if (bstate == 2) bstate = 1; | |
fb8809f4 | 112 | |
113 | if (astate != 1 && bstate != 1) | |
114 | return; | |
115 | if (astate == 1 && bstate != 1) { | |
810d12a7 | 116 | sprintf(cmd, "%s newuser -name %s -id %s", |
a6be2cf4 | 117 | prs, after[U_NAME], after[U_UID]); |
fb8809f4 | 118 | do_cmd(cmd); |
119 | return; | |
120 | } else if (astate != 1 && bstate == 1) { | |
a6be2cf4 | 121 | sprintf(cmd, "%s delete %s", prs, before[U_NAME]); |
fb8809f4 | 122 | do_cmd(cmd); |
123 | return; | |
124 | } | |
125 | ||
126 | if (beforec > U_UID && afterc > U_UID && | |
127 | strcmp(before[U_UID], after[U_UID])) { | |
128 | /* change UID, & possibly user name here */ | |
129 | exit(1); | |
130 | } | |
131 | ||
132 | if (beforec > U_NAME && afterc > U_NAME && | |
133 | strcmp(before[U_NAME], after[U_NAME])) { | |
810d12a7 | 134 | sprintf(cmd, "%s chname -oldname %s -newname %s", |
a6be2cf4 | 135 | prs, before[U_NAME], after[U_NAME]); |
fb8809f4 | 136 | do_cmd(cmd); |
137 | } | |
138 | } | |
139 | ||
140 | ||
141 | ||
142 | do_list(before, beforec, after, afterc) | |
143 | char **before; | |
144 | int beforec; | |
145 | char **after; | |
146 | int afterc; | |
147 | { | |
148 | char cmd[512]; | |
149 | int agid, bgid; | |
150 | ||
151 | cmd[0] = agid = bgid = 0; | |
152 | if (beforec > L_GID && atoi(before[L_ACTIVE]) && atoi(before[L_GROUP])) | |
153 | bgid = atoi(before[L_GID]); | |
154 | if (afterc > L_GID && atoi(after[L_ACTIVE]) && atoi(after[L_GROUP])) | |
155 | agid = atoi(after[L_GID]); | |
156 | ||
157 | if (bgid == 0 && agid != 0) { | |
810d12a7 | 158 | sprintf(cmd, |
159 | "%s create -name system:%s -id %s -owner system:administrators", | |
a6be2cf4 | 160 | prs, after[L_NAME], after[L_GID]); |
fb8809f4 | 161 | do_cmd(cmd); |
162 | return; | |
163 | } | |
164 | if (agid == 0 && bgid != 0) { | |
a6be2cf4 | 165 | sprintf(cmd, "%s delete -name system:%s", prs, before[L_NAME]); |
fb8809f4 | 166 | do_cmd(cmd); |
167 | return; | |
168 | } | |
169 | if (agid == 0 && bgid == 0) | |
170 | return; | |
171 | if (strcmp(before[L_NAME], after[L_NAME])) { | |
172 | sprintf(cmd, | |
810d12a7 | 173 | "%s chname -oldname system:%s -newname system:%s", |
a6be2cf4 | 174 | prs, before[L_NAME], after[L_NAME]); |
fb8809f4 | 175 | do_cmd(cmd); |
176 | return; | |
177 | } | |
178 | } | |
179 | ||
180 | ||
181 | do_member(before, beforec, after, afterc) | |
182 | char **before; | |
183 | int beforec; | |
184 | char **after; | |
185 | int afterc; | |
186 | { | |
187 | char cmd[512]; | |
188 | ||
189 | if (beforec == 0 && !strcmp(after[LM_TYPE], "USER")) { | |
810d12a7 | 190 | sprintf(cmd, "%s add -user %s -group system:%s", |
a6be2cf4 | 191 | prs, after[LM_MEMBER], after[LM_LIST]); |
fb8809f4 | 192 | do_cmd(cmd); |
193 | return; | |
194 | } | |
195 | if (afterc == 0 && !strcmp(before[LM_TYPE], "USER")) { | |
810d12a7 | 196 | sprintf(cmd, "%s remove -user %s -group system:%s", |
a6be2cf4 | 197 | prs, before[LM_MEMBER], before[LM_LIST]); |
fb8809f4 | 198 | do_cmd(cmd); |
199 | return; | |
200 | } | |
201 | } | |
202 | ||
203 | ||
204 | do_filesys(before, beforec, after, afterc) | |
205 | char **before; | |
206 | int beforec; | |
207 | char **after; | |
208 | int afterc; | |
209 | { | |
f633445d | 210 | if (afterc < FS_CREATE) |
211 | return; | |
5ecdaa1f | 212 | if (!strcmp("AFS", after[FS_TYPE]) && |
213 | !strncmp("/afs/", after[FS_PACK], 5) && | |
214 | atoi(after[FS_CREATE]) && | |
215 | !file_exists(after[FS_PACK])) { | |
f633445d | 216 | critical_alert("incremental", "unable to create locker %s", |
217 | after[FS_PACK]); | |
218 | } | |
fb8809f4 | 219 | } |
220 | ||
221 | ||
222 | do_quota(before, beforec, after, afterc) | |
223 | char **before; | |
224 | int beforec; | |
225 | char **after; | |
226 | int afterc; | |
227 | { | |
228 | char cmd[512]; | |
229 | ||
230 | if (!(afterc >= Q_DIRECTORY && !strncmp("/afs", after[Q_DIRECTORY], 4)) && | |
231 | !(beforec >= Q_DIRECTORY && !strncmp("/afs", before[Q_DIRECTORY], 4))) | |
232 | return; | |
daf93176 | 233 | if (afterc >= Q_LOGIN && strcmp("\\[nobody\\]", after[Q_LOGIN])) |
ac3e92fb | 234 | return; |
fb8809f4 | 235 | if (afterc != 0) { |
ac3e92fb | 236 | sprintf(cmd, "%s setquota -dir %s -quota %s", |
a6be2cf4 | 237 | fs, after[Q_DIRECTORY], after[Q_QUOTA]); |
fb8809f4 | 238 | do_cmd(cmd); |
239 | return; | |
240 | } | |
241 | } |