]> andersk Git - moira.git/blob - server/mr_sauth.c
Don't update class field in moira if the year field in the registrar's
[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 <string.h>
18 #include "mr_server.h"
19 #include <ctype.h>
20 #include <krb_et.h>
21 #include <moira.h>
22
23 extern char buf1[];
24 extern char *whoami;
25
26 /* from libmoira */
27 char *kname_unparse(char *, char *, char *);
28
29 /*
30  * Handle a MOIRA_AUTH RPC request.
31  *
32  * argv[0] is a kerberos authenticator.  Decompose it, and if
33  * successful, store the name the user authenticated to in 
34  * cl->cl_name.
35  */
36
37 void
38 do_auth(cl)
39         client *cl;
40 {
41         KTEXT_ST auth;
42         AUTH_DAT ad;
43         int status, ok;
44         char hostbuf[BUFSIZ], *host, *p;
45         extern int errno;
46
47         auth.length = cl->args->mr_argl[0];
48         memcpy((char *)auth.dat, cl->args->mr_argv[0], auth.length);
49         auth.mbz = 0;
50         if (gethostname(hostbuf, sizeof(hostbuf)) < 0)
51           com_err(whoami, errno, "Unable to get local hostname");
52         host = canonicalize_hostname(strsave(hostbuf));
53         for (p = host; *p && *p != '.'; p++)
54           if (isupper(*p))
55             *p = tolower(*p);
56         *p = 0;
57
58         if ((status = krb_rd_req (&auth, MOIRA_SNAME, host,
59                                   cl->haddr.sin_addr.s_addr, &ad, "")) != 0) {
60                 status += ERROR_TABLE_BASE_krb;
61                 cl->reply.mr_status = status;
62                 if (log_flags & LOG_RES)
63                         com_err(whoami, status, "(authentication failed)");
64                 return;
65         }
66         free(host);
67
68         memcpy(cl->kname.name, ad.pname, ANAME_SZ);
69         memcpy(cl->kname.inst, ad.pinst, INST_SZ);
70         memcpy(cl->kname.realm, ad.prealm, REALM_SZ);
71         strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm));
72
73         if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm))
74           ok = 1;
75         else
76           ok = 0;
77         /* this is in a separate function because it accesses the database */
78         status = set_krb_mapping(cl->clname, ad.pname, ok,
79                                  &cl->client_id, &cl->users_id);
80
81         if (cl->args->mr_version_no == MR_VERSION_2) {
82             strncpy(cl->entity, cl->args->mr_argv[1], 8);
83             cl->entity[8] = 0;
84         } else {
85             strcpy(cl->entity, "???");
86         }
87         memset(&ad, 0, sizeof(ad));     /* Clean up session key, etc. */
88
89         if (log_flags & LOG_RES)
90             com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d",
91                     cl->clname, cl->entity, cl->users_id, cl->client_id);
92         if (status != MR_SUCCESS)
93           cl->reply.mr_status = status;
94         else if (cl->users_id == 0)
95           cl->reply.mr_status = MR_USER_AUTH;
96 }
This page took 0.143576 seconds and 5 git commands to generate.