X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/78eff417a6abf1e71388f7b64624a66fbf53ef14..857a2dd9342266439074c6578b6a8825e56f5e29:/reg_svr/reg_svr.c diff --git a/reg_svr/reg_svr.c b/reg_svr/reg_svr.c index daea0486..d365f7ec 100644 --- a/reg_svr/reg_svr.c +++ b/reg_svr/reg_svr.c @@ -1,19 +1,38 @@ /* - * $Source$ - * $Author$ - * $Header$ + * $Source$ + * $Author$ + * $Header$ * - * Copyright (C) 1987 by the Massachusetts Institute of Technology + * Copyright (C) 1987 by the Massachusetts Institute of Technology * - * Server for user registration with SMS and Kerberos. + * Server for user registration with SMS and Kerberos. * - * This program is a client of the SMS server and the Kerberos - * admin_server, and is a server for the userreg program. + * This program is a client of the SMS server and the Kerberos + * admin_server, and is a server for the userreg program. * - * $Log$ - * Revision 1.3 1987-09-03 03:05:18 wesommer - * Version used for userreg tests. + * $Log$ + * Revision 1.9 1988-07-26 14:50:40 qjb + * Added comments and did some cleaning up in preparation for rewrite. + * This version will not run; the last version that will is 1.8. * + * Revision 1.8 88/07/20 15:39:25 mar + * find realm at runtime; don't use hard-coded one + * + * Revision 1.7 88/02/08 15:08:15 mar + * Moved header file locations + * + * Revision 1.6 87/09/21 15:19:11 wesommer + * Allow numbers, _, and . as legal characters in the username. + * + * Revision 1.5 87/09/10 22:18:32 wesommer + * Clean up output format. + * + * Revision 1.4 87/09/04 23:33:19 wesommer + * Deleted test scaffolding (second oops.) + * + * Revision 1.3 87/09/03 03:05:18 wesommer + * Version used for userreg tests. + * * Revision 1.2 87/08/22 18:39:45 wesommer * User registration server. * @@ -32,127 +51,152 @@ static char *rcsid_reg_svr_c = "$Header$"; #include #include #include +#include #include #include #include #include "ureg_err.h" #include "ureg_proto.h" -#include "../../include/sms.h" +#include "sms.h" #include "admin_server.h" -#include "admin_err.h" +#include "admin_err.h" #include -extern void abort(); +#define WHOAMI "reg_svr" /* Name of program for SMS logging */ +#define CUR_SMS_VERSION SMS_VERSION_2 /* SMS version for this program */ + + +extern int abort(); extern char *strdup(); extern char *malloc(); extern int krb_err_base; extern char admin_errmsg[]; -long now; -#define STAMP { time (&now); printf(ctime(&now)); } - -struct msg { - u_long version; - u_long request; - char *first; - char *last; - char *sealed; - int sealed_len; +extern int errno; /* Unix error number */ + +/* This is the structure used to store the packet information */ +/* Get this. The register client gets the MIT id of the registering user + in plain text, encrypts it with one-way password encryption, + concatenates that to the plain text id, and then des encrypts the + whole thing using the password encrypted id as the key! The result + goes in enc_mitid. */ +struct msg +{ + u_long version; /* SMS version */ + u_long request; /* Request */ + char *first; /* First name */ + char *last; /* Last name */ + char *enc_mitid; /* See comment above */ + int enc_mitid_len; /* Length of enc_mitid */ }; -static char retval[BUFSIZ]; +static char errmsg[BUFSIZ]; main() { - struct sockaddr_in sin; - struct servent *sp; - int s; - int status; - int addrlen, len; - char buf[BUFSIZ]; - extern int errno; - u_long seqno; - struct msg message; - extern char *whoami; - int i; - + struct servent *sp; /* Service info from /etc/services */ + int s; /* Socket descriptor */ + struct sockaddr_in sin; /* Internet style socket address */ + int addrlen; /* Size of socket address (sin) */ + char packet[BUFSIZ]; /* Buffer for packet transmission */ + int pktlen; /* Size of packet */ + u_long seqno; /* Sequence number for packet transmission */ + struct msg message; /* Storage for parsed packet */ + int status; /* General purpose error status */ + + /* Error messages sent one line at a time */ setlinebuf(stderr); - whoami = "reg_svr"; + /* Initialize user registration error table */ init_ureg_err_tbl(); - - sp = getservbyname("sms_ureg", "udp"); - if (sp == NULL) { + + /* Get service information from /etc/services */ + if ((sp = getservbyname("sms_ureg", "udp")) == NULL) + { fprintf(stderr, "Unknown service sms_ureg/udp\n"); exit(1); } - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s < 0) { + + /* Get an internet style datagram socket */ + if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) + { perror("socket"); exit(1); } bzero((char *)&sin, sizeof(sin)); - + sin.sin_family = AF_INET; sin.sin_port = sp->s_port; sin.sin_addr.s_addr = INADDR_ANY; - - if (bind(s, &sin, sizeof(sin)) < 0) { + + /* Bind a name to the socket */ + if (bind(s, &sin, sizeof(sin)) < 0) + { perror("bind"); exit(1); } - - status = sms_connect(); - if (status != 0) { - com_err("reg_svr", status, " on connect"); + + /* Connect to the SMS server */ + if ((status = sms_connect()) != SMS_SUCCESS) + { + com_err(WHOAMI, status, " on connect"); exit(1); } - status = sms_auth(); - if (status != 0) { - com_err("reg_svr", status, " on auth"); + + /* Authorize, telling the server who you are */ + if ((status = sms_auth(WHOAMI)) != SMS_SUCCESS) + { + com_err(WHOAMI, status, " on auth"); exit(1); } - for (;;) { - printf("waiting.."); - fflush(stdout); + /* Sit around waiting for requests from the client. */ + for (;;) + { + com_err(WHOAMI, 0, "Ready for next request"); addrlen = sizeof(sin); - bzero(retval, BUFSIZ); - len = recvfrom(s, buf, BUFSIZ, 0, &sin, &addrlen); - if (len < 0) { + bzero(errmsg, BUFSIZ); + /* Receive a packet into buf. */ + if ((pktlen = recvfrom(s,packet,sizeof(packet),0,&sin,&addrlen)) < 0) + { perror("recvfrom"); if (errno == EINTR) continue; - exit(1); } + /* Parse a request packet */ - status = parse_pkt(buf, len, &seqno, &message); - if (status != 0) { - len = BUFSIZ; - format_pkt(buf, &len, seqno, status, (char *)NULL); - (void) sendto(s, buf, len, 0, &sin, addrlen); + if ((status = parse_pkt(packet, pktlen, &seqno, &message)) != 0) + { + pktlen = sizeof(packet); + /* Format packet to send back to the client */ + format_pkt(packet, &pktlen, seqno, status, (char *)NULL); + /* Report the error the the client */ + (void) sendto(s, packet, pktlen, 0, &sin, addrlen); continue; } + /* do action */ - switch((int)message.request) { - case UREG_VERIFY_USER: + switch((int)message.request) + { + case UREG_VERIFY_USER: status = verify_user(&message); break; - case UREG_RESERVE_LOGIN: + case UREG_RESERVE_LOGIN: status = reserve_user(&message); break; - case UREG_SET_PASSWORD: + case UREG_SET_PASSWORD: status = set_password(&message); break; - default: + default: status = UREG_UNKNOWN_REQUEST; break; } - len = BUFSIZ; - format_pkt(buf, &len, seqno, status, retval); - sendto(s, buf, len, 0, &sin, addrlen); + /* Report what happened to client */ + pktlen = sizeof(packet); + format_pkt(packet, &pktlen, seqno, status, errmsg); + sendto(s, packet, pktlen, 0, &sin, addrlen); } } @@ -164,58 +208,82 @@ int reg_misc_len; int user_id; #define min(a,b) ((a)>(b)?(b):(a)) - + int validate_idno(message, db_mit_id, first, last) - struct msg *message; - char *db_mit_id; - char *first, *last; + struct msg *message; /* Formatted packet */ + char *db_mit_id; /* Encrypted MIT ID from SMS database */ + char *first, *last; /* First and last name for MIT ID encryption */ +/* This routine makes sure that the ID from the database matches + the ID sent accross in the packet. The information in the packet + was created in the following way: + + The plain text ID number was encrypted via crypt() resulting in + the form that would appear in the SMS database. This is + concatinated to the plain text ID so that the ID string contains + plain text ID followed by a null followed by the encrypted ID. + The whole thing is then DES encrypted using the encrypted ID as + the source of the key. + + This routine tries each encrypted ID in the database that belongs + to someone with this user's first and last name and tries to + decrypt the packet with this information. */ { - C_Block key; - Key_schedule sched; - static char decrypt[BUFSIZ]; - char recrypt[14]; - static char hashid[14]; - char idnumber[BUFSIZ]; - char *temp; - int len; - - int i; -#ifdef notdef - for (i = 0; i < message->sealed_len; i++) { - printf("%02x ", (unsigned char)message->sealed[i]); - } - printf("\n"); -#endif notdef + C_Block key; /* The key for DES en/decryption */ + Key_schedule sched; /* En/decryption schedule */ + static char decrypt[BUFSIZ]; /* Buffer to hold decrypted information */ + long decrypt_len; /* Length of decypted ID information */ + char recrypt[14]; /* Buffer to hold re-encrypted information */ + static char hashid[14]; /* Buffer to hold one-way encrypted ID */ + char idnumber[BUFSIZ]; /* Buffer to hold plain-text ID */ + char *temp; /* A temporary storage buffer */ + int len; /* */ + mit_id = 0; + /* Make the decrypted information length the same as the encrypted + information length. Both are integral multples of eight bytes + because of the DES encryption routines. */ + decrypt_len = (long)message->enc_mitid_len; + /* Get key from the one-way encrypted ID in the SMS database */ string_to_key(db_mit_id, key); + /* Get schedule from key */ key_sched(key, sched); - pcbc_encrypt(message->sealed, decrypt, message->sealed_len, sched, key, 0); - -#ifdef notdef - for (i = 0; i < message->sealed_len; i++) { - printf("%02x ", (unsigned char)decrypt[i]); - } - printf("\n"); - for (i = 0; i < message->sealed_len; i++) { - if (isprint(decrypt[i])) - printf("%c ", (unsigned char)decrypt[i]); - else printf(". "); - } - printf("\n"); -#endif notdef - (void) strncpy(idnumber, decrypt, message->sealed_len); + /* Decrypt information from packet using this key. Since decrypt_len + is an integral multiple of eight bytes, it will probably be null- + padded. */ + pcbc_encrypt(message->enc_mitid, decrypt, \ + decrypt_len, sched, key, DECRYPT); + + /* Extract the plain text and encrypted ID fields from the decrypted + packet information. */ + /* Since the decrypted information starts with the plain-text ID + followed by a null, if the decryption worked, this will only + copy the plain text part of the decrypted information. It is + important that strncpy be used because if we are not using the + correct key, there is no guarantee that a null will occur + anywhere in the string. */ + (void) strncpy(idnumber, decrypt, decrypt_len); + /* Point temp to the end of the plain text ID number. */ temp = decrypt + strlen(idnumber) + 1; - len = message->sealed_len - (temp - decrypt); - + /* Find out how much more room there is. */ + len = message->enc_mitid_len - (temp - decrypt); + /* Copy the next 14 bytes of the decrypted information into + hashid if there are 14 more bytes to copy. There will be + if we have the right key. */ (void) strncpy(hashid, temp, min(len, 14)); + /* Point temp to the end of the encrypted ID field */ temp += strlen(hashid) + 1; - len = message->sealed_len - (temp - decrypt); - + /* Find out how much more room there is. */ + len = message->enc_mitid_len - (temp - decrypt); + + /* Now compare encrypted ID's returning with an error if they + don't match. */ if (strcmp(hashid, db_mit_id)) return 1; encrypt_mitid(recrypt, idnumber, first, last); + /* Now compare encrypted plain text to ID from database. */ if (strcmp(recrypt, db_mit_id)) return 1; - + + /* We made it. */ reg_misc = temp; reg_misc_len = len; mit_id = hashid; @@ -225,33 +293,31 @@ int validate_idno(message, db_mit_id, first, last) static int status_in_db; vfy_callbk(argc, argv, p_message) - int argc; /* Should sanity check this.. */ - char **argv; - char *p_message; + int argc; /* Should sanity check this.. */ + char **argv; + char *p_message; { struct msg *message = (struct msg *)p_message; char *db_mit_id; char *firstname, *lastname; int status; -#ifdef debug - printf("Callback: %s %s %s\n", argv[8], argv[5], argv[4]); -#endif debug if (got_one) return 0; reg_status = 0; db_mit_id = argv[8]; firstname = argv[5]; lastname = argv[4]; - + status = validate_idno(message, db_mit_id, firstname, lastname); if (status) return 0; /* Nope; decryption failed */ - + status_in_db = atoi(argv[7]); reg_status = status_in_db; - - if (status_in_db != 0) { - (void) strcpy(retval, argv[0]); + + if (status_in_db != 0) + { + (void) strcpy(errmsg, argv[0]); } user_id = atoi(argv[1]); got_one = 1; @@ -265,7 +331,7 @@ encrypt_mitid(buf, idnumber, first, last) extern char *crypt(); #define _tolower(c) ((c)|0x60) - + salt[0] = _tolower(last[0]); salt[1] = _tolower(first[0]); salt[2] = 0; @@ -274,13 +340,13 @@ encrypt_mitid(buf, idnumber, first, last) } int verify_user(message) - struct msg *message; - + struct msg *message; { char *argv[3]; int status; - printf("verify_user\n"); + com_err(WHOAMI, 0, " verify_user %s %s\n", + message->first, message->last); argv[0] = "get_user_by_first_and_last"; argv[1] = message->first; argv[2] = message->last; @@ -292,62 +358,65 @@ int verify_user(message) if (!got_one && !status) status = UREG_USER_NOT_FOUND; - if (status != 0) goto punt; - + if (status != SMS_SUCCESS) goto punt; + if (reg_status == 1) status = UREG_ALREADY_REGISTERED; if (reg_status == 2) status = UREG_NO_PASSWD_YET; -punt: + punt: return status; } reserve_user(message) - struct msg *message; + struct msg *message; { char *argv[3]; int status; int i; char *login; char uid_buf[20]; + char realm[REALM_SZ]; + + com_err(WHOAMI, 0, " reserve_user %s %s\n", + message->first, message->last); - STAMP; - printf("reserve_user\n"); - argv[0] = "gufl"; /* get_user_by_first_and_last */ argv[1] = message->first; argv[2] = message->last; got_one = 0; status = sms_query_internal(3, argv, vfy_callbk, (char *)message); - - STAMP; if (status == SMS_NO_MATCH) status = UREG_USER_NOT_FOUND; if (!got_one && !status) status = UREG_USER_NOT_FOUND; - - if (status != 0) goto punt; - if (reg_status != 0) { + + if (status != SMS_SUCCESS) goto punt; + if (reg_status != 0) + { status = UREG_ALREADY_REGISTERED; goto punt; } /* * He's made it past this phase already. */ - if (status_in_db == 2) { + if (status_in_db == 2) + { status = 0; goto punt; } - /* Sanity check requested login name. */ - printf("reg_misc_len = %d\n", reg_misc_len); - - for (i = 0; i < reg_misc_len && reg_misc[i]; i++) { - if (!islower(reg_misc[i])) { + + for (i = 0; i < reg_misc_len && reg_misc[i]; i++) + { + if (!islower(reg_misc[i]) && !isdigit(reg_misc[i]) && + reg_misc[i] != '_' && reg_misc[i] != '.') + { status = UREG_INVALID_UNAME; goto punt; } } - if (i < 3 || i > 8) { + if (i < 3 || i > 8) + { status = UREG_INVALID_UNAME; goto punt; } @@ -355,99 +424,107 @@ reserve_user(message) /* Send request to kerberos admin_server for login name */ /* get keys */ - printf("get_svc_in_tkt\n"); - status = get_svc_in_tkt("register", "kerberos", "ATHENA.MIT.EDU", + if ((status = get_krbrlm(realm, 1)) != KSUCCESS) + { + status += krb_err_base; + goto punt; + } + status = get_svc_in_tkt("register", "sms", realm, "changepw", "kerberos", 1, "/etc/srvtab"); - if (status) { - status += krb_err_base; - goto punt; + if (status) + { + status += krb_err_base; + goto punt; } - STAMP; - printf("admin_call\n"); /* send set password request to kerberos admin_server */ (void) sprintf(uid_buf, "%013d", user_id); /* 13 chars of placebo */ - /* for backwards-compat. */ + /* for backwards-compat. */ status = admin_call(ADMIN_ADD_NEW_KEY_ATTR, login, "", "", uid_buf); - - if (status) { - if (status == ADMIN_SERVER_ERROR) { - printf("Server error: %s\n", admin_errmsg); - - if (strcmp(admin_errmsg, - "Principal already in kerberos database.") ==0) - status = UREG_LOGIN_USED; - } - goto punt; + + if (status) + { + if (status == ADMIN_SERVER_ERROR) + { + printf("Server error: %s\n", admin_errmsg); + + if (strcmp(admin_errmsg, + "Principal already in kerberos database.") ==0) + status = UREG_LOGIN_USED; + } + goto punt; } - + dest_tkt(); /* If valid: */ - STAMP; /* Set login name */ status = set_login(login, mit_id); - - if (status) { - com_err("set_login", status, 0); + + if (status) + { + com_err("set_login", status, (char *)0); goto punt; } /* choose post office */ - STAMP; status = choose_pobox(login); - if (status) { - com_err("choose_pobox", status, 0); + if (status) + { + com_err("choose_pobox", status, (char *)0); goto punt; } /* create group */ - STAMP; status = create_group(login); if (status == SMS_LIST) status = UREG_LOGIN_USED; - if (status) { - com_err("create_group", status, 0); + if (status) + { + com_err("create_group", status, (char *)0); goto punt; } /* set quota entry, create filsys */ - STAMP; status = alloc_filsys(login, SMS_FS_STUDENT, 0, 0); if (status == SMS_FILESYS_EXISTS) status = UREG_LOGIN_USED; - if (status) { - com_err("alloc_filsys", status, 0); + if (status) + { + com_err("alloc_filsys", status, (char *)0); goto punt; } /* set filsys and status in SMS database */ - STAMP; status = set_status_filsys(reg_misc, mit_id); - if (status) { - com_err("set_filsys", status, 0); + if (status) + { + com_err("set_filsys", status, (char *)0); goto punt; } -punt: + punt: dest_tkt(); - STAMP; - printf("reserve_user returning %s\n", error_message(status)); + + com_err(WHOAMI, status, " returned from reserve_user"); return status; } set_password(message) - struct msg *message; + struct msg *message; { char *argv[3]; int status; + char uid_buf[10]; + char realm[REALM_SZ]; + + com_err(WHOAMI, 0, " set_password %s %s\n", + message->first, message->last); - printf("set_password\n"); - /* validate that user is who he claims to be */ - + argv[0] = "get_user_by_first_and_last"; argv[1] = message->first; argv[2] = message->last; @@ -459,116 +536,145 @@ set_password(message) if (!got_one && !status) status = UREG_USER_NOT_FOUND; - if (status != 0) goto punt; - + if (status != SMS_SUCCESS) goto punt; + /* validate that state is equal to '2' (login, but no password) */ - - if (reg_status != 2) { + + if (reg_status != 2) + { status = UREG_NO_LOGIN_YET; goto punt; } - - printf("password for %s would be set to %s\n", retval ,reg_misc); - + /* get keys */ - status = get_svc_in_tkt("register", "kerberos", "ATHENA.MIT.EDU", + if ((status = get_krbrlm(realm, 1)) != KSUCCESS) + { + goto punt; + } + status = get_svc_in_tkt("register", "sms", realm, "changepw", "kerberos", 1, "/etc/srvtab"); - if (status) { - status += krb_err_base; - goto punt; + if (status) + { + status += krb_err_base; + goto punt; } + + (void) sprintf(uid_buf, "%013d", user_id); /* 13 chars of placebo */ + /* for backwards-compat. */ /* send set password request to kerberos admin_server */ - status = admin_call(ADMIN_SET_KDC_PASSWORD, retval, "", - reg_misc, "BBBBBBBBBBBBB"); - + /**####**/ + status = admin_call(ADMIN_ADD_NEW_KEY_ATTR, errmsg, "", + reg_misc, uid_buf); + if (status) goto punt; dest_tkt(); + /**#####**/ + status = set_final_status(errmsg, mit_id); - status = set_final_status(retval, mit_id); - /* reflect reply to client */ -punt: + punt: dest_tkt(); return status; } -parse_pkt(buf, len, seqnop, messagep) - char *buf; - int len; - u_long *seqnop; - struct msg *messagep; +parse_pkt(packet, pktlen, seqnop, messagep) + char *packet; + int pktlen; + u_long *seqnop; + struct msg *messagep; + /* This routine checks a packet and puts the information in it in + a structure if it is valid. */ { - if (len < 4) return UREG_BROKEN_PACKET; - bcopy(buf, (char *)&messagep->version, sizeof(long)); + if (pktlen < 4) return UREG_BROKEN_PACKET; + /* Extract the SMS version from the packet */ + bcopy(packet, (char *)&messagep->version, sizeof(long)); + /* Convert byte order from network to host */ messagep->version = ntohl(messagep->version); - if (messagep->version != 1) return UREG_WRONG_VERSION; + /* Verify version */ + if (messagep->version != CUR_SMS_VERSION) return UREG_WRONG_VERSION; - buf += 4; - len -= 4; - - if (len < 4) return UREG_BROKEN_PACKET; - bcopy(buf, (char *)seqnop, sizeof(long)); - - buf += 4; - len -= 4; + packet += 4; + pktlen -= 4; + + if (pktlen < 4) return UREG_BROKEN_PACKET; + /* Extract the sequence number from the packet */ + bcopy(packet, (char *)seqnop, sizeof(long)); - if (len < 4) return UREG_BROKEN_PACKET; - bcopy(buf, (char *)(&messagep->request), sizeof(long)); + packet += 4; + pktlen -= 4; + + if (pktlen < 4) return UREG_BROKEN_PACKET; + /* Extract the request from the packet */ + bcopy(packet, (char *)(&messagep->request), sizeof(long)); messagep->request = ntohl(messagep->request); - buf += 4; - len -= 4; + packet += 4; + pktlen -= 4; - messagep->first = buf; - - for (; *buf && len > 0; --len, ++buf) continue; - if (len <= 0) return UREG_BROKEN_PACKET; - - buf++, len--; - - messagep->last = buf; - - for (; *buf && len > 0; --len, ++buf) continue; - if (len <= 0) return UREG_BROKEN_PACKET; + /* Extract first name from the packet */ + messagep->first = packet; - buf++, len--; - - if (len <= 0) return UREG_BROKEN_PACKET; + /* Scan forward until null appears in the packet or there + is no more packet! */ + for (; *packet && pktlen > 0; --pktlen, ++packet) continue; + if (pktlen <= 0) return UREG_BROKEN_PACKET; + + /* Skip over the null */ + packet++, pktlen--; + + /* Extract last name from the packet */ + messagep->last = packet; + + for (; *packet && pktlen > 0; --pktlen, ++packet) continue; + if (pktlen <= 0) return UREG_BROKEN_PACKET; - messagep->sealed = buf; - messagep->sealed_len = len; + packet++, pktlen--; + + if (pktlen <= 0) return UREG_BROKEN_PACKET; + + /* Extract MIT id information from packet; see comment on + struct msg. */ + messagep->enc_mitid = packet; + messagep->enc_mitid_len = pktlen; return 0; } -format_pkt(buf, lenp, seqno, status, message) - char *buf; - int *lenp; - u_long seqno; - int status; - char *message; +format_pkt(packet, pktlenp, seqno, status, message) + char *packet; + int *pktlenp; + u_long seqno; + int status; + char *message; + /* This routine prepares a packet to send back to the client. */ { - u_long vers = htonl((u_long)1); + u_long vers = htonl((u_long)CUR_SMS_VERSION); status = htonl((u_long)status); - bcopy((char *)&vers, buf, sizeof(long)); - bcopy((char *)&seqno, buf+sizeof(long), sizeof(long)); - bcopy((char *)&status, buf+ 2*sizeof(long), sizeof(long)); - *lenp = sizeof(long) * 3; - (void) strcpy(buf+3*sizeof(long), message); - (*lenp) += strlen(message); + /* Put current SMS version into the packet */ + bcopy((char *)&vers, packet, sizeof(long)); + /* Put sequence number into the packet */ + bcopy((char *)&seqno, packet+sizeof(long), sizeof(long)); + /* Put error status into the packet */ + bcopy((char *)&status, packet+ 2*sizeof(long), sizeof(long)); + *pktlenp = sizeof(long) * 3; + /* Copy the message into the packet */ + (void) strcpy(packet+3*sizeof(long), message); + (*pktlenp) += strlen(message); } store_user(argc, argv, argp) - int argc; - char **argv; + int argc; + char **argv; char *argp; { char **retv = (char **) argp; int i; - for (i = 0; i < argc; i++) { - if (retv[i]) { + for (i = 0; i < argc; i++) + { + if (retv[i]) + { free(retv[i]); retv[i]=0; } @@ -576,15 +682,15 @@ store_user(argc, argv, argp) } return 0; } - + /* * Set login name of user with "idnumber" to be "username" */ set_login(username, idnumber) - char *username; - char *idnumber; + char *username; + char *idnumber; { char *argv[2]; int status, i; @@ -592,14 +698,15 @@ set_login(username, idnumber) argv[0] = "get_user_by_mitid"; argv[1] = idnumber; - - for (i=0; i<13; i++) { + + for (i=0; i<13; i++) + { retv[i] = 0; } - + status = sms_query_internal(2, argv, store_user, (char *)(retv+1)); if (status) return status; - + retv[0] = retv[1]; retv[1] = username; if (retv[4]) free(retv[4]); @@ -611,7 +718,8 @@ set_login(username, idnumber) retv[1] = 0; retv[4] = 0; - for (i=1; i<12; i++) { + for (i=1; i<12; i++) + { if (retv[i]) free(retv[i]); retv[i] = 0; } @@ -624,8 +732,8 @@ set_login(username, idnumber) */ set_status_filsys(username, idnumber) - char *username; - char *idnumber; + char *username; + char *idnumber; { char *argv[2]; int status, i; @@ -633,19 +741,20 @@ set_status_filsys(username, idnumber) argv[0] = "get_user_by_mitid"; argv[1] = idnumber; - - for (i=0; i<13; i++) { + + for (i=0; i<13; i++) + { retv[i] = 0; } - + status = sms_query_internal(2, argv, store_user, (char *)(retv+1)); if (status) return status; - + retv[0] = retv[1]; - + free(retv[4]); retv[4] = username; - + free(retv[8]); retv[8] = "2"; @@ -654,7 +763,8 @@ set_status_filsys(username, idnumber) status = sms_query("update_user", 12, retv, abort, 0); retv[4] = 0; retv[8] = 0; - for (i=1; i<12; i++) { + for (i=1; i<12; i++) + { if (retv[i]) free(retv[i]); retv[i] = 0; } @@ -665,8 +775,8 @@ set_status_filsys(username, idnumber) */ set_final_status(username, idnumber) - char *username; - char *idnumber; + char *username; + char *idnumber; { char *argv[2]; int status, i; @@ -674,16 +784,17 @@ set_final_status(username, idnumber) argv[0] = "get_user_by_mitid"; argv[1] = idnumber; - - for (i=0; i<13; i++) { + + for (i=0; i<13; i++) + { retv[i] = 0; } - + status = sms_query_internal(2, argv, store_user, (char *)(retv+1)); if (status) return status; - + retv[0] = retv[1]; - + free(retv[8]); retv[8] = "1"; @@ -691,7 +802,8 @@ set_final_status(username, idnumber) status = sms_query("update_user", 12, retv, abort, 0); retv[8] = 0; - for (i=1; i<12; i++) { + for (i=1; i<12; i++) + { if (retv[i]) free(retv[i]); retv[i] = 0; } @@ -699,10 +811,11 @@ set_final_status(username, idnumber) } create_group(login) - char *login; + char *login; { int status; - static char *cr[] = { + static char *cr[] = + { "add_user_group", 0, }; @@ -711,28 +824,14 @@ create_group(login) return sms_query_internal(2, cr, abort, 0); } + /* * Local Variables: * mode: c - * c-indent-level: 4 - * c-continued-statement-offset: 4 + * c-argdecl-indent: 2 * c-brace-offset: -4 - * c-argdecl-indent: 4 - * c-label-offset: -4 + * c-continued-statement-offset: 2 + * c-indent-level: 4 + * c-label-offset: -2 * End: */ -char *get_krbhst(a1, a2) - char *a1; - char *a2; -{ - strcpy(a1, "ICARUS.MIT.EDU"); - return 0; -} - -char *get_krbrlm(a1) - char *a1; -{ - strcpy(a1, "ATHENA.MIT.EDU"); - return 0; -} -