3 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
4 * For copying and distribution information, please see the file
9 #include <mr_private.h>
10 #include <moira_site.h>
12 #include <netinet/in.h>
18 /* This should be in the kerberos header file. */
27 * This structure holds all per-client information; one of these is
28 * allocated for each active client.
31 typedef struct _client {
32 int con; /* Connection to the client */
33 int id; /* Unique id of client */
34 struct sockaddr_in haddr; /* IP address of client */
35 char clname[MAX_K_NAME_SZ]; /* Name client authenticated to */
36 struct krbname kname; /* Parsed version of the above */
37 char entity[9]; /* client program being used */
38 int users_id; /* Moira-internal ID of authenticated user */
39 int client_id; /* Moira-internal ID of client */
40 time_t last_time_used; /* Last time connection used */
41 mr_params *tuples; /* Tuples waiting to send back to client */
42 int ntuples; /* Number of tuples waiting */
43 int tuplessize; /* Current size of tuple array */
44 int nexttuple; /* Next tuple to return */
45 int done; /* Close up next time through loop */
48 extern char krb_realm[REALM_SZ];
50 /* max length of query argument allowed */
52 /* Used to setup static argv, maximum argc */
55 /* statistics on number of queries by version number */
56 extern int newqueries;
58 /* Maximum and minimum values that will ever be chosen for IDs */
59 #define MAX_ID_VALUE 31999
60 #define MIN_ID_VALUE 100
62 /* Sleepy states for the server! */
69 /* state for the incremental update system */
70 extern int inc_running, inc_pid;
71 extern time_t inc_started, now;
72 #define INC_TIMEOUT (3 * 60) /* 3 minutes */
75 #define SQL_NO_MATCH 1403 /* oracle, not ingres (= 100) */
77 /* types needed for prototypes */
82 /* prototypes from increment.dc */
83 void incremental_init(void);
84 void next_incremental(void);
85 void incremental_update(void);
86 void incremental_flush(void);
88 /* prototypes from qrtn.dc */
90 void dosql(char *buffers[]);
91 int mr_open_database(void);
92 void mr_close_database(void);
93 int mr_process_query(client *cl, char *name, int argc, char *argv_ro[],
94 int (*action)(int, char *[], void *), void *actarg);
95 int mr_check_access(client *cl, char *name, int argc, char *argv_ro[]);
96 void sanity_check_queries(void);
97 int set_krb_mapping(char *name, char *login, int ok, int *kid, int *uid);
98 int find_member(char *list_type, int list_id, client *cl);
99 int do_for_all_rows(char *query, int count,
100 int (*action)(int, char *[], void *), void *actarg);
101 void build_qual(char *fmt, int argc, char *argv[], char *qual);
104 /* prototyoes from qsupport.dc */
105 int set_pop_usage(int id, int cnt);
107 /* prototypes from qvalidate.dc */
108 void sanity_check_database(void);
109 int add_string(char *name);
110 int convert_wildcards(char *arg);
112 /* prototypes from mr_main.c */
113 void clist_delete(client *cp);
115 /* prototypes from mr_sauth.c */
116 void do_auth(client *cl, mr_params req);
118 /* prototypes from mr_scall.c */
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);
125 /* prototypes from mr_shutdown.c */
127 void do_shutdown(client *cl);
129 /* prototypes from mr_util.c */
130 char *requote(char *buf, char *cp, int len);
131 void log_args(char *tag, int version, int argc, char **argv);
132 void mr_com_err(const char *whoami, long code, const char *fmt, va_list pvar);
133 int mr_trim_args(int argc, char **argv);
134 char **mr_copy_args(char **argv, int argc);
135 void *xmalloc(size_t);
136 void *xrealloc(void *, size_t);
138 /* prototypes from qaccess.pc */
139 int access_user(struct query *q, char *argv[], client *cl);
140 int access_login(struct query *q, char *argv[], client *cl);
141 int access_list(struct query *q, char *argv[], client *cl);
142 int access_visible_list(struct query *q, char *argv[], client *cl);
143 int access_vis_list_by_name(struct query *q, char *argv[], client *cl);
144 int access_member(struct query *q, char *argv[], client *cl);
145 int access_qgli(struct query *q, char *argv[], client *cl);
146 int access_service(struct query *q, char *argv[], client *cl);
147 int access_filesys(struct query *q, char *argv[], client *cl);
148 int access_host(struct query *q, char *argv[], client *cl);
149 int access_ahal(struct query *q, char *argv[], client *cl);
150 int access_snt(struct query *q, char *argv[], client *cl);
152 /* prototypes from qfollow.pc */
153 int followup_fix_modby(struct query *q, struct save_queue *sq,
154 struct validate *v, int (*action)(int, char **, void *),
155 void *actarg, client *cl);
156 int followup_gpob(struct query *q, struct save_queue *sq, struct validate *v,
157 int (*action)(int, char **, void *), void *actarg,
159 int followup_glin(struct query *q, struct save_queue *sq, struct validate *v,
160 int (*action)(int, char **, void *), void *actarg,
162 int followup_gzcl(struct query *q, struct save_queue *sq, struct validate *v,
163 int (*action)(int, char **, void *), void *actarg,
165 int followup_gsha(struct query *q, struct save_queue *sq, struct validate *v,
166 int (*action)(int, char **, void *), void *actarg,
168 int followup_gqot(struct query *q, struct save_queue *sq, struct validate *v,
169 int (*action)(int, char **, void *), void *actarg,
171 int followup_gpce(struct query *q, struct save_queue *sq, struct validate *v,
172 int (*action)(int, char **, void *), void *actarg,
174 int followup_guax(struct query *q, struct save_queue *sq, struct validate *v,
175 int (*action)(int, char **, void *), void *actarg,
177 int followup_gsnt(struct query *q, struct save_queue *sq, struct validate *v,
178 int (*action)(int, char **, void *), void *actarg,
180 int followup_ghst(struct query *q, struct save_queue *sq, struct validate *v,
181 int (*action)(int, char **, void *), void *actarg,
184 int followup_ausr(struct query *q, char *argv[], client *cl);
185 int followup_aqot(struct query *q, char *argv[], client *cl);
186 int followup_dqot(struct query *q, char *argv[], client *cl);
187 int followup_uuac(struct query *q, char *argv[], client *cl);
189 int set_modtime(struct query *q, char *argv[], client *cl);
190 int set_modtime_by_id(struct query *q, char *argv[], client *cl);
191 int set_finger_modtime(struct query *q, char *argv[], client *cl);
192 int set_pobox_modtime(struct query *q, char *argv[], client *cl);
193 int set_uppercase_modtime(struct query *q, char *argv[], client *cl);
194 int set_mach_modtime_by_id(struct query *q, char *argv[], client *cl);
195 int set_cluster_modtime_by_id(struct query *q, char *argv[], client *cl);
196 int set_serverhost_modtime(struct query *q, char *argv[], client *cl);
197 int set_nfsphys_modtime(struct query *q, char *argv[], client *cl);
198 int set_filesys_modtime(struct query *q, char *argv[], client *cl);
199 int set_zephyr_modtime(struct query *q, char *argv[], client *cl);
200 int _sdl_followup(struct query *q, char *argv[], client *cl);
201 int trigger_dcm(struct query *q, char *argv[], client *cl);
203 /* prototypes from qsetup.pc */
204 int prefetch_value(struct query *q, char *argv[], client *cl);
205 int prefetch_filesys(struct query *q, char *argv[], client *cl);
206 int setup_ausr(struct query *q, char *argv[], client *cl);
207 int setup_dusr(struct query *q, char *argv[], client *cl);
208 int setup_spop(struct query *q, char *argv[], client *cl);
209 int setup_dpob(struct query *q, char *argv[], client *cl);
210 int setup_dmac(struct query *q, char *argv[], client *cl);
211 int setup_dclu(struct query *q, char *argv[], client *cl);
212 int setup_alis(struct query *q, char *argv[], client *cl);
213 int setup_dlis(struct query *q, char *argv[], client *cl);
214 int setup_dsin(struct query *q, char *argv[], client *cl);
215 int setup_dshi(struct query *q, char *argv[], client *cl);
216 int setup_afil(struct query *q, char *argv[], client *cl);
217 int setup_ufil(struct query *q, char *argv[], client *cl);
218 int setup_dfil(struct query *q, char *argv[], client *cl);
219 int setup_aftg(struct query *q, char *argv[], client *cl);
220 int setup_dnfp(struct query *q, char *argv[], client *cl);
221 int setup_dqot(struct query *q, char *argv[], client *cl);
222 int setup_akum(struct query *q, char *argv[], client *cl);
223 int setup_dsnt(struct query *q, char *argv[], client *cl);
224 int setup_ahst(struct query *q, char *argv[], client *cl);
225 int setup_ahal(struct query *q, char *argv[], client *cl);
227 /* prototypes from qsupport.pc */
228 int set_pobox(struct query *q, char *argv[], client *cl);
229 int add_member_to_list(struct query *q, char *argv[], client *cl);
230 int delete_member_from_list(struct query *q, char *argv[], client *cl);
231 int register_user(struct query *q, char *argv[], client *cl);
233 int get_list_info(struct query *q, char **argv, client *cl,
234 int (*action)(int, char *[], void *), void *actarg);
235 int get_ace_use(struct query *q, char **argv, client *cl,
236 int (*action)(int, char *[], void *), void *actarg);
237 int qualified_get_lists(struct query *q, char **argv, client *cl,
238 int (*action)(int, char *[], void *), void *actarg);
239 int get_members_of_list(struct query *q, char **argv, client *cl,
240 int (*action)(int, char *[], void *), void *actarg);
241 int get_end_members_of_list(struct query *q, char **argv, client *cl,
242 int (*action)(int, char *[], void *),
244 int qualified_get_server(struct query *q, char **argv, client *cl,
245 int (*action)(int, char *[], void *), void *actarg);
246 int qualified_get_serverhost(struct query *q, char **argv, client *cl,
247 int (*action)(int, char *[], void *),
249 int count_members_of_list(struct query *q, char **argv, client *cl,
250 int (*action)(int, char *[], void *), void *actarg);
251 int get_lists_of_member(struct query *q, char **argv, client *cl,
252 int (*action)(int, char *[], void *), void *actarg);
254 /* prototypes from qvalidate.pc */
255 /* from qvalidate.dc */
256 int validate_fields(struct query *q, char *argv[], struct valobj *vo, int n);
257 int validate_row(struct query *q, char *argv[], struct validate *v);