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 extern int krb_err_base;
17 #include <mit-copyright.h>
19 #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 extern int krb_err_base;
42 static char *unknown = "???";
48 bzero(&cl->kname, sizeof(cl->kname));
50 if (cl->entity && cl->entity != unknown) {
55 auth.length = cl->args->sms_argl[0];
56 bcopy(cl->args->sms_argv[0], (char *)auth.dat, auth.length);
59 if ((status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
60 &ad, "")) != KSUCCESS) {
61 status += krb_err_base;
62 cl->reply.sms_status = status;
63 if (log_flags & LOG_RES)
64 com_err(whoami, status, "(authentication failed)");
67 bcopy(ad.pname, cl->kname.name, ANAME_SZ);
68 bcopy(ad.pinst, cl->kname.inst, INST_SZ);
69 bcopy(ad.prealm, cl->kname.realm, REALM_SZ);
71 (void) strcpy(buf, ad.pname);
73 (void) strcat(buf, ".");
74 (void) strcat(buf, ad.pinst);
76 (void) strcat(buf, "@");
77 (void) strcat(buf, ad.prealm);
78 if (cl->clname) free((char *)cl->clname);
80 cl->clname = (char *)malloc((unsigned)(strlen(buf)+1));
81 (void) strcpy(cl->clname, buf);
82 bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */
84 cl->users_id = get_users_id(cl->kname.name);
86 if (cl->args->sms_version_no == SMS_VERSION_2) {
87 unsigned len = strlen(cl->args->sms_argv[1]) + 1;
89 cl->entity = (char *)malloc(len);
90 bcopy(cl->args->sms_argv[1], cl->entity, len+1);
95 if (log_flags & LOG_RES)
96 com_err(whoami, 0, "Authenticated to %s using %s, id %d",
97 cl->clname, cl->entity, cl->users_id);
98 if (cl->users_id == 0)
99 cl->reply.sms_status = SMS_USER_AUTH;