]> andersk Git - moira.git/blob - server/mr_sauth.c
check realm on kerberos tickets
[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 #include <mit-copyright.h>
17 #include <strings.h>
18 #include "sms_server.h"
19 #include <krb_et.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         static char *unknown = "???";
42         
43         if (cl->clname) {
44                 free(cl->clname);
45                 cl->clname = 0;
46                 cl->users_id = 0;
47                 bzero(&cl->kname, sizeof(cl->kname));
48         }
49         if (cl->entity && cl->entity != unknown) {
50                 free(cl->entity);
51                 cl->entity = 0;
52         }
53         
54         auth.length = cl->args->sms_argl[0];
55         bcopy(cl->args->sms_argv[0], (char *)auth.dat, auth.length);
56         auth.mbz = 0;
57         
58         if ((status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
59                                  &ad, "")) != 0) {
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)");
64                 return;
65         }
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);
69         
70         (void) strcpy(buf, ad.pname);
71         if(ad.pinst[0]) {
72                 (void) strcat(buf, ".");
73                 (void) strcat(buf, ad.pinst);
74         }
75         (void) strcat(buf, "@");
76         (void) strcat(buf, ad.prealm);
77         if (cl->clname) free((char *)cl->clname);
78         
79         cl->clname = (char *)malloc((unsigned)(strlen(buf)+1));
80         (void) strcpy(cl->clname, buf);
81
82         if (!strcmp(ad.prealm, krb_realm))
83           cl->users_id = get_users_id(cl->kname.name);
84
85         if (cl->args->sms_version_no == SMS_VERSION_2) {
86             unsigned len = strlen(cl->args->sms_argv[1]) + 1;
87
88             cl->entity = (char *)malloc(len);
89             bcopy(cl->args->sms_argv[1], cl->entity, len+1);
90         } else {
91             cl->entity = unknown;
92         }
93         bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */
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.048453 seconds and 5 git commands to generate.