6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
13 static char *rcsid_sms_sauth_c = "$Header$";
16 #include <mit-copyright.h>
18 #include "sms_server.h"
23 extern char *malloc();
26 * Handle a SMS_AUTH RPC request.
28 * argv[0] is a kerberos authenticator. Decompose it, and if
29 * successful, store the name the user authenticated to in
40 char buf[REALM_SZ+INST_SZ+ANAME_SZ];
41 static char *unknown = "???";
47 bzero(&cl->kname, sizeof(cl->kname));
49 if (cl->entity && cl->entity != unknown) {
54 auth.length = cl->args->sms_argl[0];
55 bcopy(cl->args->sms_argv[0], (char *)auth.dat, auth.length);
58 if ((status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
60 status += ERROR_TABLE_BASE_krb;
61 cl->reply.sms_status = status;
62 if (log_flags & LOG_RES)
63 com_err(whoami, status, "(authentication failed)");
66 bcopy(ad.pname, cl->kname.name, ANAME_SZ);
67 bcopy(ad.pinst, cl->kname.inst, INST_SZ);
68 bcopy(ad.prealm, cl->kname.realm, REALM_SZ);
70 (void) strcpy(buf, ad.pname);
72 (void) strcat(buf, ".");
73 (void) strcat(buf, ad.pinst);
75 (void) strcat(buf, "@");
76 (void) strcat(buf, ad.prealm);
77 if (cl->clname) free((char *)cl->clname);
79 cl->clname = (char *)malloc((unsigned)(strlen(buf)+1));
80 (void) strcpy(cl->clname, buf);
81 bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */
83 cl->users_id = get_users_id(cl->kname.name);
85 if (cl->args->sms_version_no == SMS_VERSION_2) {
86 unsigned len = strlen(cl->args->sms_argv[1]) + 1;
88 cl->entity = (char *)malloc(len);
89 bcopy(cl->args->sms_argv[1], cl->entity, len+1);
94 if (log_flags & LOG_RES)
95 com_err(whoami, 0, "Authenticated to %s using %s, id %d",
96 cl->clname, cl->entity, cl->users_id);
97 if (cl->users_id == 0)
98 cl->reply.sms_status = SMS_USER_AUTH;