]>
Commit | Line | Data |
---|---|---|
7ac48069 | 1 | /* $Id$ |
eab30d01 | 2 | * |
7ac48069 | 3 | * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology |
4 | * For copying and distribution information, please see the file | |
5 | * <mit-copyright.h>. | |
eab30d01 | 6 | */ |
7 | ||
7ac48069 | 8 | #include <moira.h> |
85330553 | 9 | #include <mr_private.h> |
d548a4e7 | 10 | #include <moira_site.h> |
e688520a | 11 | #include <moira_schema.h> |
7ac48069 | 12 | |
13 | #include <netinet/in.h> | |
14 | ||
98a7b0ee | 15 | #include <stdarg.h> |
5dbd09a0 | 16 | |
cb974713 | 17 | #ifdef HAVE_KRB4 |
7ac48069 | 18 | #include <krb.h> |
cb974713 | 19 | #else |
20 | #include <mr_krb.h> | |
21 | #endif | |
991417e4 | 22 | #include <krb5.h> |
7ac48069 | 23 | |
8691463b | 24 | enum clstate { CL_ACCEPTING, CL_ACTIVE, CL_CLOSING }; |
25 | ||
0311b667 | 26 | /* |
27 | * This structure holds all per-client information; one of these is | |
28 | * allocated for each active client. | |
29 | */ | |
5d354f89 | 30 | |
0fa91a0a | 31 | typedef struct _client { |
85330553 | 32 | int con; /* Connection to the client */ |
5eaef520 | 33 | int id; /* Unique id of client */ |
34 | struct sockaddr_in haddr; /* IP address of client */ | |
8691463b | 35 | enum clstate state; /* State of the connection */ |
5eaef520 | 36 | char clname[MAX_K_NAME_SZ]; /* Name client authenticated to */ |
ed00e35e | 37 | char entity[USERS_MODWITH_SIZE]; /* client program being used */ |
59ec8dae | 38 | int users_id; /* Moira-internal ID of authenticated user */ |
85330553 | 39 | int client_id; /* Moira-internal ID of client */ |
ed00e35e | 40 | int proxy_id; /* client_id of orig user, if proxied */ |
c44ddfa7 | 41 | int version; /* Max query version known by client */ |
5eaef520 | 42 | time_t last_time_used; /* Last time connection used */ |
8691463b | 43 | mr_params req; /* Current request */ |
85330553 | 44 | mr_params *tuples; /* Tuples waiting to send back to client */ |
45 | int ntuples; /* Number of tuples waiting */ | |
46 | int tuplessize; /* Current size of tuple array */ | |
47 | int nexttuple; /* Next tuple to return */ | |
8691463b | 48 | char *hsbuf; /* Buffer for initial connection handshaking */ |
49 | int hslen; /* Length of data in hsbuf */ | |
0fa91a0a | 50 | } client; |
51 | ||
b4b129dd | 52 | struct mxentry |
53 | { | |
54 | char *name; | |
55 | int pref; | |
56 | }; | |
57 | ||
cb974713 | 58 | extern char *krb_realm; |
90052a6f | 59 | |
60 | /* max length of query argument allowed */ | |
9608e722 | 61 | #define ARGLEN 257 |
58e1747c | 62 | /* Used to setup static argv, maximum argc */ |
4f6b1a05 | 63 | #define QMAXARGS 25 |
7a2ebcdf | 64 | |
65 | /* statistics on number of queries by version number */ | |
85330553 | 66 | extern int newqueries; |
7a2ebcdf | 67 | |
edba5c0f | 68 | /* Maximum and minimum values that will be used for uids and gids */ |
b79fc9f5 | 69 | #define MAX_ID_VALUE 131072 |
fcd67f6a | 70 | #define MIN_ID_VALUE 100 |
87f17989 | 71 | |
72 | /* Sleepy states for the server! */ | |
73 | #define AWAKE 0 | |
74 | #define SLEEPY 1 | |
75 | #define ASLEEP 2 | |
76 | #define GROGGY 3 | |
77 | extern int dormant; | |
78 | ||
13f6b8bb | 79 | /* state for the incremental update system */ |
80 | extern int inc_running, inc_pid; | |
81 | extern time_t inc_started, now; | |
82 | #define INC_TIMEOUT (3 * 60) /* 3 minutes */ | |
03c05291 | 83 | |
84 | ||
85 | #define SQL_NO_MATCH 1403 /* oracle, not ingres (= 100) */ | |
86 | ||
7ac48069 | 87 | /* types needed for prototypes */ |
88 | struct query; | |
89 | struct validate; | |
90 | struct valobj; | |
91 | ||
03c05291 | 92 | /* prototypes from increment.dc */ |
93 | void incremental_init(void); | |
94 | void next_incremental(void); | |
95 | void incremental_update(void); | |
96 | void incremental_flush(void); | |
97 | ||
98 | /* prototypes from qrtn.dc */ | |
99 | void dbmserr(void); | |
100 | void dosql(char *buffers[]); | |
101 | int mr_open_database(void); | |
102 | void mr_close_database(void); | |
103 | int mr_process_query(client *cl, char *name, int argc, char *argv_ro[], | |
7ac48069 | 104 | int (*action)(int, char *[], void *), void *actarg); |
03c05291 | 105 | int mr_check_access(client *cl, char *name, int argc, char *argv_ro[]); |
106 | void sanity_check_queries(void); | |
107 | int set_krb_mapping(char *name, char *login, int ok, int *kid, int *uid); | |
f3c08a60 | 108 | int find_member(char *list_type, int list_id, client *cl); |
7ac48069 | 109 | int do_for_all_rows(char *query, int count, |
110 | int (*action)(int, char *[], void *), void *actarg); | |
263a36d4 | 111 | char *build_qual(char *fmt, int argc, char *argv[]); |
03c05291 | 112 | |
113 | ||
114 | /* prototyoes from qsupport.dc */ | |
115 | int set_pop_usage(int id, int cnt); | |
116 | ||
117 | /* prototypes from qvalidate.dc */ | |
118 | void sanity_check_database(void); | |
119 | int add_string(char *name); | |
120 | int convert_wildcards(char *arg); | |
121 | ||
122 | /* prototypes from mr_main.c */ | |
123 | void clist_delete(client *cp); | |
124 | ||
125 | /* prototypes from mr_sauth.c */ | |
8691463b | 126 | void do_auth(client *cl); |
ed00e35e | 127 | void do_proxy(client *cl); |
991417e4 | 128 | void do_krb5_auth(client *cl); |
03c05291 | 129 | |
130 | /* prototypes from mr_scall.c */ | |
85330553 | 131 | void do_client(client *cl); |
132 | void client_reply(client *cl, long status); | |
133 | void client_return_tuple(client *cl, int argc, char **argv); | |
134 | void client_read(client *cl); | |
135 | void client_write(client *cl); | |
03c05291 | 136 | |
137 | /* prototypes from mr_shutdown.c */ | |
138 | void sigshut(int); | |
139 | void do_shutdown(client *cl); | |
140 | ||
141 | /* prototypes from mr_util.c */ | |
e688520a | 142 | char *requote(char *buf); |
03c05291 | 143 | void log_args(char *tag, int version, int argc, char **argv); |
98a7b0ee | 144 | void mr_com_err(const char *whoami, long code, const char *fmt, va_list pvar); |
03c05291 | 145 | int mr_trim_args(int argc, char **argv); |
146 | char **mr_copy_args(char **argv, int argc); | |
85330553 | 147 | void *xmalloc(size_t); |
148 | void *xrealloc(void *, size_t); | |
e688520a | 149 | char *xstrdup(char *); |
7ac48069 | 150 | |
151 | /* prototypes from qaccess.pc */ | |
152 | int access_user(struct query *q, char *argv[], client *cl); | |
153 | int access_login(struct query *q, char *argv[], client *cl); | |
f659afb2 | 154 | int access_spob(struct query *q, char *argv[], client *cl); |
7ac48069 | 155 | int access_list(struct query *q, char *argv[], client *cl); |
156 | int access_visible_list(struct query *q, char *argv[], client *cl); | |
157 | int access_vis_list_by_name(struct query *q, char *argv[], client *cl); | |
158 | int access_member(struct query *q, char *argv[], client *cl); | |
159 | int access_qgli(struct query *q, char *argv[], client *cl); | |
160 | int access_service(struct query *q, char *argv[], client *cl); | |
161 | int access_filesys(struct query *q, char *argv[], client *cl); | |
162 | int access_host(struct query *q, char *argv[], client *cl); | |
163 | int access_ahal(struct query *q, char *argv[], client *cl); | |
164 | int access_snt(struct query *q, char *argv[], client *cl); | |
1a9a0a59 | 165 | int access_printer(struct query *q, char *argv[], client *cl); |
d7ddc011 | 166 | int access_zephyr(struct query *q, char *argv[], client *cl); |
2fb668b0 | 167 | int access_container(struct query *q, char *argv[], client *cl); |
26e6ea51 | 168 | int access_update_user(struct query *q, char *argv[], client *cl); |
7b12515f | 169 | int check_mail_string(char *mailstring); |
b4b129dd | 170 | struct mxentry *getmxrecords(const char *); |
7ac48069 | 171 | |
172 | /* prototypes from qfollow.pc */ | |
173 | int followup_fix_modby(struct query *q, struct save_queue *sq, | |
174 | struct validate *v, int (*action)(int, char **, void *), | |
175 | void *actarg, client *cl); | |
176 | int followup_gpob(struct query *q, struct save_queue *sq, struct validate *v, | |
177 | int (*action)(int, char **, void *), void *actarg, | |
178 | client *cl); | |
179 | int followup_glin(struct query *q, struct save_queue *sq, struct validate *v, | |
180 | int (*action)(int, char **, void *), void *actarg, | |
181 | client *cl); | |
59c3208b | 182 | int followup_gsin(struct query *q, struct save_queue *sq, struct validate *v, |
183 | int (*action)(int, char **, void *), void *actarg, | |
184 | client *cl); | |
7ac48069 | 185 | int followup_gzcl(struct query *q, struct save_queue *sq, struct validate *v, |
186 | int (*action)(int, char **, void *), void *actarg, | |
187 | client *cl); | |
188 | int followup_gsha(struct query *q, struct save_queue *sq, struct validate *v, | |
189 | int (*action)(int, char **, void *), void *actarg, | |
190 | client *cl); | |
191 | int followup_gqot(struct query *q, struct save_queue *sq, struct validate *v, | |
192 | int (*action)(int, char **, void *), void *actarg, | |
193 | client *cl); | |
7ac48069 | 194 | int followup_guax(struct query *q, struct save_queue *sq, struct validate *v, |
195 | int (*action)(int, char **, void *), void *actarg, | |
196 | client *cl); | |
197 | int followup_gsnt(struct query *q, struct save_queue *sq, struct validate *v, | |
198 | int (*action)(int, char **, void *), void *actarg, | |
199 | client *cl); | |
200 | int followup_ghst(struct query *q, struct save_queue *sq, struct validate *v, | |
201 | int (*action)(int, char **, void *), void *actarg, | |
202 | client *cl); | |
1a9a0a59 | 203 | int followup_gpsv(struct query *q, struct save_queue *sq, struct validate *v, |
204 | int (*action)(int, char **, void *), void *actarg, | |
205 | client *cl); | |
2fb668b0 | 206 | int followup_gcon(struct query *q, struct save_queue *sq, struct validate *v, |
207 | int (*action)(int, char **, void *), void *actarg, | |
208 | client *cl); | |
3b634eb3 | 209 | int followup_get_user(struct query *q, struct save_queue *sq, |
210 | struct validate *v, int (*action)(int, char **, void *), | |
211 | void *actarg, client *cl); | |
7ac48069 | 212 | |
213 | int followup_ausr(struct query *q, char *argv[], client *cl); | |
214 | int followup_aqot(struct query *q, char *argv[], client *cl); | |
215 | int followup_dqot(struct query *q, char *argv[], client *cl); | |
7ac48069 | 216 | |
217 | int set_modtime(struct query *q, char *argv[], client *cl); | |
218 | int set_modtime_by_id(struct query *q, char *argv[], client *cl); | |
219 | int set_finger_modtime(struct query *q, char *argv[], client *cl); | |
220 | int set_pobox_modtime(struct query *q, char *argv[], client *cl); | |
221 | int set_uppercase_modtime(struct query *q, char *argv[], client *cl); | |
222 | int set_mach_modtime_by_id(struct query *q, char *argv[], client *cl); | |
223 | int set_cluster_modtime_by_id(struct query *q, char *argv[], client *cl); | |
224 | int set_serverhost_modtime(struct query *q, char *argv[], client *cl); | |
225 | int set_nfsphys_modtime(struct query *q, char *argv[], client *cl); | |
226 | int set_filesys_modtime(struct query *q, char *argv[], client *cl); | |
227 | int set_zephyr_modtime(struct query *q, char *argv[], client *cl); | |
69eb9470 | 228 | int set_service_modtime(struct query *q, char *argv[], client *cl); |
7ac48069 | 229 | int _sdl_followup(struct query *q, char *argv[], client *cl); |
85330553 | 230 | int trigger_dcm(struct query *q, char *argv[], client *cl); |
7ac48069 | 231 | |
232 | /* prototypes from qsetup.pc */ | |
233 | int prefetch_value(struct query *q, char *argv[], client *cl); | |
234 | int prefetch_filesys(struct query *q, char *argv[], client *cl); | |
235 | int setup_ausr(struct query *q, char *argv[], client *cl); | |
236 | int setup_dusr(struct query *q, char *argv[], client *cl); | |
7ac48069 | 237 | int setup_dpob(struct query *q, char *argv[], client *cl); |
238 | int setup_dmac(struct query *q, char *argv[], client *cl); | |
239 | int setup_dclu(struct query *q, char *argv[], client *cl); | |
240 | int setup_alis(struct query *q, char *argv[], client *cl); | |
241 | int setup_dlis(struct query *q, char *argv[], client *cl); | |
242 | int setup_dsin(struct query *q, char *argv[], client *cl); | |
243 | int setup_dshi(struct query *q, char *argv[], client *cl); | |
244 | int setup_afil(struct query *q, char *argv[], client *cl); | |
245 | int setup_ufil(struct query *q, char *argv[], client *cl); | |
246 | int setup_dfil(struct query *q, char *argv[], client *cl); | |
247 | int setup_aftg(struct query *q, char *argv[], client *cl); | |
248 | int setup_dnfp(struct query *q, char *argv[], client *cl); | |
249 | int setup_dqot(struct query *q, char *argv[], client *cl); | |
4f6b1a05 | 250 | int setup_asnt(struct query *q, char *argv[], client *cl); |
7ac48069 | 251 | int setup_dsnt(struct query *q, char *argv[], client *cl); |
c1fe2b12 | 252 | int setup_ghst(struct query *q, char *argv[], client *cl); |
7ac48069 | 253 | int setup_ahst(struct query *q, char *argv[], client *cl); |
254 | int setup_ahal(struct query *q, char *argv[], client *cl); | |
2884200f | 255 | int setup_uhha(struct query *q, char *argv[], client *cl); |
256 | int setup_aprn(struct query *q, char *argv[], client *cl); | |
1a9a0a59 | 257 | int setup_dpsv(struct query *q, char *argv[], client *cl); |
2fb668b0 | 258 | int setup_dcon(struct query *q, char *argv[], client *cl); |
73155abd | 259 | int setup_acon(struct query *q, char *argv[], client *cl); |
260 | int setup_scli(struct query *q, char *argv[], client *cl); | |
9910965a | 261 | int setup_aali(struct query *q, char *argv[], client *cl); |
7ac48069 | 262 | |
263 | /* prototypes from qsupport.pc */ | |
264 | int set_pobox(struct query *q, char *argv[], client *cl); | |
17cb3de8 | 265 | int set_pobox_pop(struct query *q, char *argv[], client *cl); |
7ac48069 | 266 | int add_member_to_list(struct query *q, char *argv[], client *cl); |
267 | int delete_member_from_list(struct query *q, char *argv[], client *cl); | |
20541c25 | 268 | int tag_member_of_list(struct query *q, char *argv[], client *cl); |
7ac48069 | 269 | int register_user(struct query *q, char *argv[], client *cl); |
77eb4bdf | 270 | int do_user_reservation(struct query *q, char *argv[], client *cl); |
2fb668b0 | 271 | int update_container(struct query *q, char *argv[], client *cl); |
73155abd | 272 | int set_container_list(struct query *q, char *argv[], client *cl); |
7ac48069 | 273 | |
7ac48069 | 274 | int get_ace_use(struct query *q, char **argv, client *cl, |
275 | int (*action)(int, char *[], void *), void *actarg); | |
d3051625 | 276 | int get_host_by_owner(struct query *q, char **argv, client *cl, |
277 | int (*action)(int, char *[], void *), void *actarg); | |
7902e669 | 278 | int get_user_account_by_sponsor(struct query *q, char **argv, client *cl, |
279 | int (*action)(int, char *[], void *), | |
280 | void *actarg); | |
7ac48069 | 281 | int qualified_get_lists(struct query *q, char **argv, client *cl, |
282 | int (*action)(int, char *[], void *), void *actarg); | |
283 | int get_members_of_list(struct query *q, char **argv, client *cl, | |
284 | int (*action)(int, char *[], void *), void *actarg); | |
7ac48069 | 285 | int qualified_get_server(struct query *q, char **argv, client *cl, |
286 | int (*action)(int, char *[], void *), void *actarg); | |
287 | int qualified_get_serverhost(struct query *q, char **argv, client *cl, | |
288 | int (*action)(int, char *[], void *), | |
289 | void *actarg); | |
290 | int count_members_of_list(struct query *q, char **argv, client *cl, | |
291 | int (*action)(int, char *[], void *), void *actarg); | |
292 | int get_lists_of_member(struct query *q, char **argv, client *cl, | |
293 | int (*action)(int, char *[], void *), void *actarg); | |
77eb4bdf | 294 | int get_user_reservations(struct query *q, char **argv, client *cl, |
295 | int (*action)(int, char *[], void *), void *actarg); | |
296 | int get_user_by_reservation(struct query *q, char **argv, client *cl, | |
297 | int (*action)(int, char *[], void *), | |
298 | void *actarg); | |
2fb668b0 | 299 | int get_machines_of_container(struct query *q, char **argv, client *cl, |
300 | int (*action)(int, char *[], void *), | |
301 | void *actarg); | |
302 | int get_subcontainers_of_container(struct query *q, char **argv, client *cl, | |
303 | int (*action)(int, char *[], void *), | |
304 | void *actarg); | |
305 | ||
7ac48069 | 306 | |
307 | /* prototypes from qvalidate.pc */ | |
7ac48069 | 308 | int validate_fields(struct query *q, char *argv[], struct valobj *vo, int n); |
309 | int validate_row(struct query *q, char *argv[], struct validate *v); |