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