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