]> andersk Git - moira.git/blob - server/mr_sauth.c
added copyright message
[moira.git] / server / mr_sauth.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1987 by the Massachusetts Institute of Technology
7  *      For copying and distribution information, please see the file
8  *      <mit-copyright.h>.
9  *
10  */
11
12 #ifndef lint
13 static char *rcsid_sms_sauth_c = "$Header$";
14 #endif lint
15
16 extern int krb_err_base;
17 #include <mit-copyright.h>
18 #include <strings.h>
19 #include "sms_server.h"
20
21 extern char buf1[];
22 extern char *whoami;
23 extern char *malloc();
24
25 /*
26  * Handle a SMS_AUTH RPC request.
27  *
28  * argv[0] is a kerberos authenticator.  Decompose it, and if
29  * successful, store the name the user authenticated to in 
30  * cl->cl_name.
31  */
32
33 void
34 do_auth(cl)
35         client *cl;
36 {
37         KTEXT_ST auth;
38         AUTH_DAT ad;
39         int status;
40         char buf[REALM_SZ+INST_SZ+ANAME_SZ];
41         extern int krb_err_base;
42         static char *unknown = "???";
43         
44         if (cl->clname) {
45                 free(cl->clname);
46                 cl->clname = 0;
47                 cl->users_id = 0;
48                 bzero(&cl->kname, sizeof(cl->kname));
49         }
50         if (cl->entity && cl->entity != unknown) {
51                 free(cl->entity);
52                 cl->entity = 0;
53         }
54         
55         auth.length = cl->args->sms_argl[0];
56         bcopy(cl->args->sms_argv[0], (char *)auth.dat, auth.length);
57         auth.mbz = 0;
58         
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)");
65                 return;
66         }
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);
70         
71         (void) strcpy(buf, ad.pname);
72         if(ad.pinst[0]) {
73                 (void) strcat(buf, ".");
74                 (void) strcat(buf, ad.pinst);
75         }
76         (void) strcat(buf, "@");
77         (void) strcat(buf, ad.prealm);
78         if (cl->clname) free((char *)cl->clname);
79         
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. */
83
84         cl->users_id = get_users_id(cl->kname.name);
85
86         if (cl->args->sms_version_no == SMS_VERSION_2) {
87             unsigned len = strlen(cl->args->sms_argv[1]) + 1;
88
89             cl->entity = (char *)malloc(len);
90             bcopy(cl->args->sms_argv[1], cl->entity, len+1);
91         } else {
92             cl->entity = unknown;
93         }
94
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;
100 }
This page took 0.042338 seconds and 5 git commands to generate.