6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
11 static char *rcsid_sms_sauth_c = "$Header$";
14 extern int krb_err_base;
16 #include "sms_server.h"
20 extern char *malloc();
23 * Handle a SMS_AUTH RPC request.
25 * argv[0] is a kerberos authenticator. Decompose it, and if
26 * successful, store the name the user authenticated to in
37 char buf[REALM_SZ+INST_SZ+ANAME_SZ];
38 extern int krb_err_base;
39 static char *unknown = "???";
45 bzero(&cl->kname, sizeof(cl->kname));
47 if (cl->entity && cl->entity != unknown) {
52 auth.length = cl->args->sms_argl[0];
53 bcopy(cl->args->sms_argv[0], (char *)auth.dat, auth.length);
56 if ((status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
57 &ad, "")) != KSUCCESS) {
58 status += krb_err_base;
59 cl->reply.sms_status = status;
60 if (log_flags & LOG_RES)
61 com_err(whoami, status, "(authentication failed)");
64 bcopy(ad.pname, cl->kname.name, ANAME_SZ);
65 bcopy(ad.pinst, cl->kname.inst, INST_SZ);
66 bcopy(ad.prealm, cl->kname.realm, REALM_SZ);
68 (void) strcpy(buf, ad.pname);
70 (void) strcat(buf, ".");
71 (void) strcat(buf, ad.pinst);
73 (void) strcat(buf, "@");
74 (void) strcat(buf, ad.prealm);
75 if (cl->clname) free((char *)cl->clname);
77 cl->clname = (char *)malloc((unsigned)(strlen(buf)+1));
78 (void) strcpy(cl->clname, buf);
79 bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */
81 cl->users_id = get_users_id(cl->kname.name);
83 if (cl->args->sms_version_no == SMS_VERSION_2) {
84 unsigned len = strlen(cl->args->sms_argv[1]) + 1;
86 cl->entity = (char *)malloc(len);
87 bcopy(cl->args->sms_argv[1], cl->entity, len+1);
92 if (log_flags & LOG_RES)
93 com_err(whoami, 0, "Authenticated to %s using %s, id %d",
94 cl->clname, cl->entity, cl->users_id);
95 if (cl->users_id == 0)
96 cl->reply.sms_status = SMS_USER_AUTH;