6 * Copyright (C) 1987, 1988 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
10 * Server for user registration with Moira and Kerberos.
12 * This program is a client of the Kerberos admin_server and a
13 * server for the userreg program. It is not a client of the
14 * Moira server as it is linked with libmoiraglue which bypasses
15 * the network protocol.
19 static char *rcsid_reg_svr_c = "$Header$";
22 #include <mit-copyright.h>
27 #include <sys/types.h>
36 #include "moira_site.h"
39 extern char admin_errmsg[];
41 void reg_com_err_hook();
47 struct msg message; /* Storage for parsed packet */
48 int status = SUCCESS; /* Error status */
49 char retval[BUFSIZ]; /* Buffer to hold return message for client */
51 void req_initialize(); /* Initialize request layer */
52 void get_request(); /* Get a request */
53 void report(); /* Respond to a request */
58 /* Error messages sent one line at a time */
61 set_com_err_hook(reg_com_err_hook);
63 /* Initialize com_err error tables */
67 initialize_gdss_error_table();
69 /* Use com_err or output to stderr for all log messages. */
71 com_err(whoami, 0, "*** Debugging messages enabled. ***");
74 /* Set the name of our kerberos ticket file */
75 krb_set_tkt_string("/tmp/tkt_ureg");
77 /* Connect to the Moira server */
78 if ((status = mr_connect(MOIRA_SERVER)) != MR_SUCCESS)
80 com_err(whoami, status, " on mr_connect");
84 /* Authorize, telling the server who you are */
85 if ((status = mr_auth(whoami)) != MR_SUCCESS)
87 com_err(whoami, status, " on mr_auth");
91 journal = fopen(REGJOURNAL, "a");
92 if (journal == NULL) {
93 com_err(whoami, errno, " while opening journal file");
97 /* Allow request layer to initialize */
100 /* Sit around waiting for requests from the client. */
103 get_request(&message);
105 switch((int)message.request)
107 case UREG_VERIFY_USER:
108 status = verify_user(&message,retval);
110 case UREG_RESERVE_LOGIN:
111 status = reserve_user(&message,retval);
113 case UREG_SET_PASSWORD:
115 status = set_password(&message,retval);
118 status = set_identity(&message,retval);
120 case UREG_GET_SECURE:
121 status = get_secure(&message,retval);
123 case UREG_SET_SECURE:
124 status = set_secure(&message,retval);
127 status = UREG_UNKNOWN_REQUEST;
128 critical_alert(FAIL_INST,"Unknown request %d from userreg.",
133 /* Report what happened to client */
134 report(status, retval);
138 int parse_encrypted(message,data)
139 struct msg *message; /* Formatted packet */
140 struct db_data *data; /* Data from the Moira database */
141 /* This routine makes sure that the ID from the database matches
142 the ID sent accross in the packet. The information in the packet
143 was created in the following way:
145 The database used to contain encrypted IDs. Now we don't encrypt
146 them in the database, although there are still some encrypted IDs
149 The plain text ID number was encrypted via EncryptID() resulting
150 in the form that would appear in the Moira database. This is
151 concatinated to the plain text ID so that the ID string contains plain
152 text ID followed by a null followed by the encrypted ID. Other
153 information such as the username or password is appended. The whole
154 thing is then DES encrypted using the encrypted ID as the source of
157 This routine tries each ID in the database that belongs
158 to someone with this user's first and last name and tries to
159 decrypt the packet with this information. If it succeeds, it returns
160 zero and initializes all the fields of the formatted packet structure
161 that depend on the encrypted information. */
163 des_cblock key; /* The key for DES en/decryption */
164 des_key_schedule sched; /* En/decryption schedule */
165 static char decrypt[BUFSIZ]; /* Buffer to hold decrypted information */
166 long decrypt_len; /* Length of decypted ID information */
167 char recrypt[14]; /* Buffer to hold re-encrypted information */
168 static char hashid[14]; /* Buffer to hold one-way encrypted ID */
169 char idnumber[BUFSIZ]; /* Buffer to hold plain-text ID */
170 char *temp; /* A temporary string pointer */
171 int len; /* Keeps track of length left in packet */
172 int status = SUCCESS; /* Error status */
175 com_err(whoami, 0, "Entering parse_encrypted");
178 /* Make the decrypted information length the same as the encrypted
179 information length. Both are integral multples of eight bytes
180 because of the DES encryption routines. */
181 decrypt_len = (long)message->encrypted_len;
183 /* Get key from the possibly one-way encrypted ID in the Moira database */
184 if (data->mit_id[0] >= '0' && data->mit_id[0] <= '9') {
187 EncryptID(buf, data->mit_id, message->first, message->last);
188 des_string_to_key(buf, key);
190 des_string_to_key(data->mit_id, key);
192 /* Get schedule from key */
193 des_key_sched(key, sched);
194 /* Decrypt information from packet using this key. Since decrypt_len
195 is an integral multiple of eight bytes, it will probably be null-
197 des_pcbc_encrypt(message->encrypted, decrypt, decrypt_len,
198 sched, key, DES_DECRYPT);
200 /* Extract the plain text and encrypted ID fields from the decrypted
201 packet information. */
202 /* Since the decrypted information starts with the plain-text ID
203 followed by a null, if the decryption worked, this will only
204 copy the plain text part of the decrypted information. It is
205 important that strncpy be used because if we are not using the
206 correct key, there is no guarantee that a null will occur
207 anywhere in the string. */
208 (void) strncpy(idnumber,decrypt,(int)decrypt_len);
209 /* Check that the idnumber of a mismatched decryption doesn't overflow
212 if (strlen(idnumber) != 9) {
214 com_err(whoami, 0, "idnumber wrong size, probable user mismatch\n");
218 /* Point temp to the end of the plain text ID number. */
219 temp = decrypt + strlen(idnumber) + 1;
220 /* Find out how much more packet there is. */
221 len = message->encrypted_len - (temp - decrypt);
222 /* Copy the next CRYPT_LEN bytes of the decrypted information into
223 hashid if there are CRYPT_LEN more bytes to copy. There will be
224 if we have the right key. */
225 (void) strncpy(hashid, temp, min(len, CRYPT_LEN));
226 /* Point temp to the end of the encrypted ID field */
227 temp += strlen(hashid) + 1;
228 /* Find out how much more room there is. */
229 len = message->encrypted_len - (temp - decrypt);
231 /* Now compare encrypted ID and clear text ID for a match. */
232 if (strcmp(hashid, data->mit_id) &&
233 strcmp(idnumber, data->mit_id))
236 if (status == SUCCESS)
238 /* We made it. Now we can finish initializing message. */
239 /* Point leftover to whatever is left over! */
240 message->leftover = temp;
241 message->leftover_len = len;
242 /* Since we know we have the right user, fill in the information
243 from the Moira database. */
244 message->db.reg_status = data->reg_status;
245 (void) strncpy(message->db.uid,data->uid, sizeof(message->db.uid));
246 (void) strncpy(message->db.mit_id,data->mit_id,
247 sizeof(message->db.mit_id));
248 (void) strncpy(message->db.login,data->login, sizeof(message->db.login));
253 com_err(whoami, status, " in parse_encrypted");
255 com_err(whoami, status, "parse_encrypted succeeded");
261 int db_callproc(argc,argv,queue)
262 int argc; /* Number of arguments returned by Moira */
263 char *argv[]; /* Arguments returned by Moira */
264 struct save_queue *queue; /* Queue to save information in */
265 /* This function is called by mr_query after each tuple found. It is
266 used by find_user to cache information about each user found. */
268 struct db_data *data; /* Structure to store the information in */
269 int status = SUCCESS; /* Error status */
272 com_err(whoami, 0, "Entering db_callproc.");
279 "Wrong number of arguments returned from get_user_account_by_name.");
284 /* extract the needed information from the results of the Moira query */
285 data = (struct db_data *)malloc(sizeof(struct db_data));
286 data->reg_status = atoi(argv[U_STATE]);
287 (void) strncpy(data->login,argv[U_NAME],sizeof(data->login));
288 (void) strncpy(data->mit_id,argv[U_MITID],sizeof(data->mit_id));
289 (void) strncpy(data->uid,argv[U_UID],sizeof(data->uid));
291 fprintf(stderr,"Found in database:\n");
292 fprintf(stderr," Registration status: %d\n",data->reg_status);
293 fprintf(stderr," login: %s\n",data->login);
294 fprintf(stderr," MIT ID: %s\n",data->mit_id);
295 fprintf(stderr," uid: %s\n",data->uid);
297 sq_save_data(queue,data);
303 int find_user(message)
304 struct msg *message; /* Formatted packet structure */
305 /* This routine verifies that a user is allowed to register by finding
306 him/her in the Moira database. It returns the status of the Moira
307 query that it calls. */
309 #define GUBN_ARGS 2 /* Arguements needed by get_user_by_name */
310 char *q_name; /* Name of query */
311 int q_argc; /* Number of arguments for query */
312 char *q_argv[GUBN_ARGS]; /* Arguments to query */
313 int status = SUCCESS; /* Query return status */
315 struct save_queue *queue; /* Queue to hold Moira data */
316 struct db_data *data; /* Structure for data for one tuple */
317 short verified = FALSE; /* Have we verified the user? */
319 /* Zero the mit_id field in the formatted packet structure. This
320 being zeroed means that no user was found. */
321 bzero(message->db.mit_id,sizeof(message->db.mit_id));
323 if (status == SUCCESS)
325 /* Get ready to make an Moira query */
326 q_name = "get_user_account_by_name";
327 q_argc = GUBN_ARGS; /* #defined in this routine */
328 q_argv[0] = message->first;
329 q_argv[1] = message->last;
331 /* Create queue to hold information */
335 status = mr_query(q_name,q_argc,q_argv,db_callproc,(char *)queue);
338 fprintf(stderr," %d returned by get_user_by_name\n",status);
341 if (status == MR_SUCCESS)
343 /* Traverse the list, freeing data as we go. If sq_get_data()
344 returns zero if there is no more data on the queue. */
345 while (sq_get_data(queue,&data))
348 /* parse_encrypted returns zero on success */
349 verified = (parse_encrypted(message,data) == SUCCESS);
354 /* Destroy the queue */
359 fprintf(stderr,"Returned from find_user\n");
360 fprintf(stderr," MIT ID: %s\n", message->db.mit_id);
361 fprintf(stderr," Registration status: %d\n",message->db.reg_status);
362 fprintf(stderr," uid: %s\n",message->db.uid);
363 fprintf(stderr," login: %s\n",message->db.login);
364 fprintf(stderr," Status from query: %d\n",status);
370 int verify_user(message,retval)
373 /* This routine determines whether a user is in the databse and returns
374 his state so that other routines can figure out whether he is the
375 correct state for various transactions. */
378 int status = SUCCESS; /* Return status */
380 /* Log that we are about to veryify user */
381 com_err(whoami, 0, "verifying user %s %s",message->first,message->last);
383 /* Figure out what user (if any) can be found based on the
384 encrypted information in the packet. (See the comment on
385 parse_encrypted().) */
387 status = find_user(message);
389 /* If Moira coudn't find the user */
390 if (status == MR_NO_MATCH)
391 status = UREG_USER_NOT_FOUND;
392 else if (status == MR_SUCCESS)
394 /* If the information sent over in the packet did not point to a
395 valid user, the mit_id field in the formatted packet structure
397 if (message->db.mit_id[0] == NULL)
398 status = UREG_USER_NOT_FOUND;
399 /* If the user was found but the registration has already started,
400 use this as the status */
403 switch (message->db.reg_status)
405 case US_NO_LOGIN_YET:
409 status = UREG_ALREADY_REGISTERED;
412 status = UREG_NO_PASSWD_YET;
415 status = UREG_DELETED;
418 status = UREG_NOT_ALLOWED;
421 status = UREG_ENROLLED;
423 case US_ENROLL_NOT_ALLOWED:
424 status = UREG_ENROLL_NOT_ALLOWED;
426 case US_HALF_ENROLLED:
427 status = UREG_HALF_ENROLLED;
430 status = UREG_MISC_ERROR;
431 critical_alert(FAIL_INST,"Bad user state %d for login %s.",
432 message->db.reg_status, message->db.login);
435 /* Set retval to the login name so that the client can use
436 it in the error message it will give the user. */
437 (void) strcpy(retval,message->db.login);
442 com_err(whoami, status, " returned from verify_user");
444 com_err(whoami, 0, "User verified");
451 unsigned int status = SUCCESS; /* Return status */
452 static char krbrealm[REALM_SZ]; /* kerberos realm name */
453 static char hostbuf[BUFSIZ], *host; /* local hostname in principal fmt */
454 static int inited = 0;
458 com_err(whoami, 0, "Entering ureg_kadm_init");
463 bzero(krbrealm, sizeof(krbrealm));
464 if (status = krb_get_lrealm(krbrealm, 1)) {
465 status += krb_err_base;
466 com_err(whoami, status, " fetching kerberos realm");
469 if (gethostname(hostbuf, sizeof(hostbuf)) < 0)
470 com_err(whoami, errno, "getting local hostname");
471 host = canonicalize_hostname(strsave(hostbuf));
472 for (p = host; *p && *p != '.'; p++)
478 /* Get keys for interacting with Kerberos admin server. */
479 /* principal, instance, realm, service, service instance, life, file */
480 if (status = krb_get_svc_in_tkt(MOIRA_SNAME, host, krbrealm, PWSERV_NAME,
481 KADM_SINST, 1, KEYFILE))
482 status += krb_err_base;
484 if (status != SUCCESS)
485 com_err(whoami, status, " while get admin tickets");
488 com_err(whoami, status, "Succeeded in getting admin tickets");
492 if (status == SUCCESS) {
493 if ((status = kadm_init_link(PWSERV_NAME, KADM_SINST, krbrealm)) !=
495 com_err(whoami, status, " while initializing kadmin connection");
502 int null_callproc(argc,argv,message)
506 /* This routine is a null callback that should be used for queries that
507 do not return tuples. If it ever gets called, something is wrong. */
509 critical_alert(FAIL_INST,"Something returned from an update query.");
514 * This routine reserves a principal in kerberos by setting up a
515 * principal with a random initial key.
517 int reserve_krb(login)
520 int status = SUCCESS;
523 u_long *lkey = (u_long *)key;
526 com_err(whoami, 0, "Entering reserve_krb");
529 if ((status = ureg_kadm_init()) == SUCCESS) {
530 bzero((char *)&new, sizeof(new));
531 SET_FIELD(KADM_DESKEY, new.fields);
532 SET_FIELD(KADM_NAME, new.fields);
534 (void) des_random_key(key);
535 new.key_low = htonl(lkey[0]);
536 new.key_high = htonl(lkey[1]);
537 strcpy(new.name, login);
539 com_err(whoami, 0, "Creating kerberos principal for %s", login);
540 status = kadm_add(&new);
541 if (status != KADM_SUCCESS)
542 com_err(whoami, status, " while reserving principal");
544 bzero((char *)&new, sizeof(new));
553 * This routine reserves a principal in kerberos by setting up a
554 * principal with a random initial key.
556 int setpass_krb(login, password)
560 int status = SUCCESS;
563 u_long *lkey = (u_long *)key;
565 if ((status = ureg_kadm_init()) == SUCCESS) {
566 bzero((char *)&new, sizeof(new));
567 SET_FIELD(KADM_DESKEY, new.fields);
568 SET_FIELD(KADM_NAME, new.fields);
570 (void) des_string_to_key(password, key);
571 new.key_low = htonl(lkey[0]);
572 new.key_high = htonl(lkey[1]);
573 strcpy(new.name, login);
575 com_err(whoami, 0, "Setting password for %s", login);
576 /* First arguement is not used if user has modify privileges */
577 if ((status = kadm_mod(&new, &new)) != KADM_SUCCESS) {
578 if (status == KADM_NOENTRY) {
580 "kerberos principal doesn't exist; creating");
581 if ((status = kadm_add(&new)) != KADM_SUCCESS)
582 com_err(whoami, status,
583 " while creating kerberos principal");
586 com_err(whoami, status, " while setting password");
594 int reserve_user(message,retval)
598 int q_argc; /* Number of arguments to query */
599 char *q_argv[3]; /* Arguments to Moira query */
600 char *q_name; /* Name of Moira query */
601 int status = SUCCESS; /* General purpose error status */
602 char fstype_buf[7]; /* Buffer to hold fs_type, a 16 bit number */
603 char *login; /* The login name the user wants */
604 register int i; /* A counter */
606 /* Log that we are about to reserve a user. */
607 com_err(whoami, 0, "reserving user %s %s",
608 message->first, message->last);
610 /* Check to make sure that we can verify this user. */
611 if ((status = verify_user(message,retval)) == SUCCESS)
613 /* Get the requested login name from leftover packet information. */
614 login = message->leftover;
616 /* Check the login name for validity. The login name is currently
617 is allowed to contain lowercase letters in any position and
618 and numbers and underscore characters in any position but the
620 if ((strlen(login) < MIN_UNAME) || (strlen(login) > MAX_UNAME))
621 status = UREG_INVALID_UNAME;
623 if (status == SUCCESS)
624 if ((login[0] == '_') || isdigit(login[0]))
625 status = UREG_INVALID_UNAME;
627 if (status == SUCCESS)
629 for (i = 0; i < strlen(login); i++)
630 if (!islower(login[i]) && !isdigit(login[i]) &&
633 status = UREG_INVALID_UNAME;
637 if (status == SUCCESS)
639 /* Now that we have a valid user with a valid login... */
641 /* First, try to reserve the user in Moira. */
642 (void) sprintf(fstype_buf,"%d",MR_FS_STUDENT);
643 q_name = "register_user";
644 q_argv[0] = message->db.uid;
646 q_argv[2] = fstype_buf;
648 status = mr_query(q_name,q_argc,q_argv,null_callproc,(char *)0);
655 status = UREG_LOGIN_USED;
658 status = UREG_MISC_ERROR;
661 critical_alert(FAIL_INST,"%s returned from register_user.",
662 error_message(status));
663 status = UREG_MISC_ERROR;
668 if (status == SUCCESS)
671 * Moira login was successfully created; try to reserve kerberos
674 * If this routine fails, store the login in the retval so
675 * that it can be used in the client-side error message.
677 if ((status = reserve_krb(login)) != SUCCESS)
678 (void) strcpy(retval, login);
682 com_err(whoami, status, " returned from reserve_user");
684 com_err(whoami, 0, "User reserved");
690 int set_final_status(message)
692 /* This routine updates a user's registration status to fully
696 char *q_name; /* Name of Moira query */
697 int q_argc; /* Number of arguments for Moira query */
698 char *q_argv[2]; /* Arguments to get user by uid */
699 char state[7]; /* Can hold a 16 bit integer */
700 int status; /* Error status */
702 if (message->request == UREG_SET_PASSWORD)
703 (void) sprintf(state,"%d",US_REGISTERED);
704 else if (message->db.reg_status == US_NO_LOGIN_YET)
705 (void) sprintf(state,"%d",US_ENROLLED);
707 (void) sprintf(state,"%d",US_ENROLL_NOT_ALLOWED);
709 login = message->db.login;
710 com_err(whoami, 0, "Setting final status for %s to %s", login, state);
712 q_name = "update_user_status";
716 if ((status = mr_query(q_name, q_argc, q_argv, null_callproc,
717 (char *)0)) != MR_SUCCESS) {
718 if (status == MR_DEADLOCK)
719 status = UREG_MISC_ERROR;
721 critical_alert(FAIL_INST,"%s returned from update_user_status.",
722 error_message(status));
725 com_err(whoami, status, " returned from set_final_status");
727 com_err(whoami, 0, "Final status set");
732 int set_password(message,retval)
735 /* This routine is used to set the initial password for the new user. */
737 int status = SUCCESS; /* Return status */
738 char *passwd; /* User's password */
740 com_err(whoami, 0, "setting password %s %s",
741 message->first, message->last);
743 status = verify_user(message,retval);
745 /* Don't set the password unless the registration status of the user
746 is that he exists and has no password. */
747 if (status == SUCCESS)
748 status = UREG_NO_LOGIN_YET;
749 if (((int)message->request == UREG_SET_PASSWORD &&
750 status == UREG_NO_PASSWD_YET) ||
751 ((int)message->request == UREG_GET_KRB &&
752 status == UREG_HALF_ENROLLED))
754 /* User is in proper state for this transaction. */
756 passwd = message->leftover;
759 if ((status = setpass_krb(message->db.login, passwd)) != SUCCESS)
760 /* If failure, allow login name to be used in client
762 (void) strcpy(retval,message->db.login);
764 /* Otherwise, mark user as finished. */
765 status = set_final_status(message);
769 com_err(whoami, status, " returned from set_passwd");
771 com_err(whoami, 0, "Password set");
777 int getuserinfo(argc, argv, qargv)
782 int status = SUCCESS;
786 critical_alert(FAIL_INST,
787 "Wrong number of args returned from get_user_by_uid");
790 qargv[U_NAME] = strsave(argv[U_NAME]);
791 for (i = 1; i < U_MODTIME; i++)
792 qargv[i+1] = strsave(argv[i]);
793 qargv[U_MODTIME+1] = NULL;
799 int set_identity(message,retval)
803 int q_argc; /* Number of arguments to query */
804 char *q_argv[U_END]; /* Arguments to Moira query */
805 char *q_name; /* Name of Moira query */
806 int status = SUCCESS; /* General purpose error status */
807 char fstype_buf[7]; /* Buffer to hold fs_type, a 16 bit number */
808 char *login; /* The login name the user wants */
809 register int i; /* A counter */
811 /* Log that we are about to reserve a user. */
812 com_err(whoami, 0, "setting identity %s %s",
813 message->first, message->last);
815 /* Check to make sure that we can verify this user. */
816 status = verify_user(message,retval);
817 if (status == SUCCESS || status == UREG_NOT_ALLOWED)
820 /* Get the requested login name from leftover packet information. */
821 login = message->leftover;
823 /* Check the login name for validity. The login name is currently
824 is allowed to contain lowercase letters in any position and
825 and numbers and underscore characters in any position but the
827 if ((strlen(login) < MIN_UNAME) || (strlen(login) > MAX_UNAME))
828 status = UREG_INVALID_UNAME;
830 if (status == SUCCESS)
831 if ((login[0] == '_') || isdigit(login[0]))
832 status = UREG_INVALID_UNAME;
833 if (status == SUCCESS)
835 for (i = 0; i < strlen(login); i++)
836 if (!islower(login[i]) && !isdigit(login[i]) &&
839 status = UREG_INVALID_UNAME;
843 if (status == SUCCESS)
845 /* Now that we have a valid user with a valid login... */
847 q_argv[0] = message->db.uid;
848 status = mr_query("get_user_account_by_uid", 1, q_argv,
849 getuserinfo, q_argv);
850 if (status != SUCCESS) {
851 com_err(whoami, status, " while getting user info");
854 q_argv[U_NAME+1] = login;
855 q_argv[U_STATE+1] = "7";
856 q_argv[U_SIGNATURE+1] = "";
857 status = mr_query("update_user_account", U_MODTIME+1, q_argv,
858 null_callproc, NULL);
866 status = UREG_LOGIN_USED;
869 status = UREG_MISC_ERROR;
872 critical_alert(FAIL_INST,"%s returned from update_user_account.",
873 error_message(status));
874 status = UREG_MISC_ERROR;
878 if (status == SUCCESS)
880 /* Moira login was successfully created; try to reserve kerberos
882 /* If this routine fails, store the login in the retval so
883 that it can be used in the client-side error message. */
884 if ((status = reserve_krb(login)) != SUCCESS)
885 (void) strcpy(retval, login);
889 com_err(whoami, status, " returned from set_identity");
891 com_err(whoami, 0, "Identity set");
897 void reg_com_err_hook(whoami, code, fmt, pvar)
904 fputs(whoami, stderr);
908 fputs(error_message(code), stderr);
911 _doprnt(fmt, pvar, stderr);
918 /* Find out of someone's secure instance password is set.
919 * Returns UREG_ALREADY_REGISTERED if set, SUCCESS (0) if not.
922 int get_secure(message, retval)
929 com_err(whoami, 0, "checking status of secure password for %s",
931 argv[0] = message->first;
932 status = mr_query("get_user_account_by_login", 1, argv, getuserinfo, argv);
933 if (status != SUCCESS) {
934 com_err(whoami, status, " while getting user info");
937 if (atoi(argv[U_SECURE + 1]))
938 return UREG_ALREADY_REGISTERED;
943 /* Set someone's secure instance password. */
945 int set_secure(message, retval)
950 char *argv[U_END], hostbuf[256], *bp, *p, buf[512], *passwd, *id;
956 u_long *lkey = (u_long *)key;
958 static int inited = 0;
963 if (gethostname(hostbuf, sizeof(hostbuf)) < 0)
964 com_err(whoami, errno, "getting local hostname");
965 host = strsave(krb_get_phost(hostbuf));
968 com_err(whoami, 0, "setting secure passwd for %s", message->first);
969 argv[0] = message->first;
970 status = mr_query("get_user_account_by_login", 1, argv, getuserinfo, argv);
971 if (status != SUCCESS) {
972 com_err(whoami, status, " while getting user info");
975 if (atoi(argv[U_SECURE + 1])) {
976 com_err(whoami, UREG_ALREADY_REGISTERED, "in set_secure()");
977 return UREG_ALREADY_REGISTERED;
980 bp = message->encrypted;
981 /* round up to word boundary */
982 bp = (char *)((((u_long)bp + 3) >> 2) << 2);
984 creds.length = ntohl(*((int *)bp));
986 bcopy(bp, creds.dat, creds.length);
991 com_err(whoami, 0, "Cred: length %d", creds.length);
992 for (i = 0; i < creds.length; i += 16)
993 com_err(whoami, 0, " %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
994 creds.dat[i+0], creds.dat[i+1], creds.dat[i+2], creds.dat[i+3],
995 creds.dat[i+4], creds.dat[i+5], creds.dat[i+6], creds.dat[i+7],
996 creds.dat[i+8], creds.dat[i+9], creds.dat[i+10], creds.dat[i+11],
997 creds.dat[i+12], creds.dat[i+13], creds.dat[i+14], creds.dat[i+15]);
1000 status = krb_rd_req(&creds, "changepw", host, cur_req_sender(),
1003 status += krb_err_base;
1004 com_err(whoami, status, " verifying credentials in set_secure()");
1008 message->leftover_len = ntohl(*((int*)(bp)));
1010 message->leftover = bp;
1012 des_key_sched(auth.session, keys);
1013 des_pcbc_encrypt(message->leftover, buf, message->leftover_len,
1014 keys, auth.session, 0);
1017 passwd = index(buf, ',');
1020 com_err(whoami, 0, "Got id: %s, passwd %d chars", id, strlen(passwd));
1023 if (strcmp(id, argv[U_MITID + 1])) {
1026 EncryptID(buf, id, argv[U_FIRST+1], argv[U_LAST+1]);
1027 if (strcmp(buf, argv[U_MITID + 1])) {
1028 status = UREG_USER_NOT_FOUND;
1029 com_err(whoami, status, "IDs mismatch: %s (%s), %s", id, buf,
1035 /* now do actual password setting stuff */
1037 if ((status = ureg_kadm_init()) != SUCCESS) {
1038 com_err(whoami, status, "initing kadm stuff");
1042 bzero((char *)&kv, sizeof(kv));
1043 SET_FIELD(KADM_DESKEY, kv.fields);
1044 SET_FIELD(KADM_NAME, kv.fields);
1045 SET_FIELD(KADM_INST, kv.fields);
1046 (void) des_string_to_key(passwd, key);
1047 kv.key_low = htonl(lkey[0]);
1048 kv.key_high = htonl(lkey[1]);
1049 strcpy(kv.name, message->first);
1050 strcpy(kv.instance, "extra");
1052 if ((status = kadm_add(&kv)) != KADM_SUCCESS) {
1053 com_err(whoami, status, " while creating kerberos principal");
1057 argv[0] = message->first;
1059 gettimeofday(&now, NULL);
1060 sprintf(buf, "%d", now.tv_sec);
1061 status = mr_query("update_user_security_status", 2, argv, getuserinfo, argv);
1062 if (status != SUCCESS) {
1063 com_err(whoami, status, " while updating user status");