]> andersk Git - moira.git/blob - server/mr_sauth.c
moved file definition
[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 char *kname_unparse();
26
27 /*
28  * Handle a SMS_AUTH RPC request.
29  *
30  * argv[0] is a kerberos authenticator.  Decompose it, and if
31  * successful, store the name the user authenticated to in 
32  * cl->cl_name.
33  */
34
35 void
36 do_auth(cl)
37         client *cl;
38 {
39         KTEXT_ST auth;
40         AUTH_DAT ad;
41         int status, ok;
42         char buf[REALM_SZ+INST_SZ+ANAME_SZ];
43         
44         auth.length = cl->args->sms_argl[0];
45         bcopy(cl->args->sms_argv[0], (char *)auth.dat, auth.length);
46         auth.mbz = 0;
47         
48         if ((status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
49                                  &ad, "")) != 0) {
50                 status += ERROR_TABLE_BASE_krb;
51                 cl->reply.sms_status = status;
52                 if (log_flags & LOG_RES)
53                         com_err(whoami, status, "(authentication failed)");
54                 return;
55         }
56
57         bcopy(ad.pname, cl->kname.name, ANAME_SZ);
58         bcopy(ad.pinst, cl->kname.inst, INST_SZ);
59         bcopy(ad.prealm, cl->kname.realm, REALM_SZ);
60         strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm));
61
62         if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm))
63           ok = 1;
64         else
65           ok = 0;
66         /* this is in a separate function because it accesses the database */
67         set_krb_mapping(cl->clname, ad.pname, ok,
68                         &cl->client_id, &cl->users_id);
69
70         if (cl->args->sms_version_no == SMS_VERSION_2) {
71             bcopy(cl->args->sms_argv[1], cl->entity, 8);
72             cl->entity[8] = 0;
73         } else {
74             strcpy(cl->entity, "???");
75         }
76         bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */
77
78         if (log_flags & LOG_RES)
79             com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d",
80                     cl->clname, cl->entity, cl->users_id, cl->client_id);
81         if (cl->users_id == 0)
82           cl->reply.sms_status = SMS_USER_AUTH;
83 }
84
85
86 /* Turn a principal, instance, realm triple into a single non-ambiguous 
87  * string.  This is the inverse of kname_parse().  It returns a pointer
88  * to a static buffer, or NULL on error.
89  */
90
91 char *kname_unparse(p, i, r)
92 char *p;
93 char *i;
94 char *r;
95 {
96     static char name[MAX_K_NAME_SZ];
97     char *s;
98
99     s = name;
100     if (!p || strlen(p) > ANAME_SZ)
101       return(NULL);
102     while (*p) {
103         switch (*p) {
104         case '@':
105             *s++ = '\\';
106             *s++ = '@';
107             break;
108         case '.':
109             *s++ = '\\';
110             *s++ = '.';
111             break;
112         case '\\':
113             *s++ = '\\';
114             *s++ = '\\';
115             break;
116         default:
117             *s++ = *p;
118         }
119         p++;
120     }
121     if (i && *i) {
122         if (strlen(i) > INST_SZ)
123           return(NULL);
124         *s++ = '.';
125         while (*i) {
126             switch (*i) {
127             case '@':
128                 *s++ = '\\';
129                 *s++ = '@';
130                 break;
131             case '.':
132                 *s++ = '\\';
133                 *s++ = '.';
134                 break;
135             case '\\':
136                 *s++ = '\\';
137                 *s++ = '\\';
138                 break;
139             default:
140                 *s++ = *i;
141             }
142             i++;
143         }
144     }
145     *s++ = '@';
146     if (!r || strlen(r) > REALM_SZ)
147       return(NULL);
148     while (*r) {
149         switch (*r) {
150         case '@':
151             *s++ = '\\';
152             *s++ = '@';
153             break;
154         case '\\':
155             *s++ = '\\';
156             *s++ = '\\';
157             break;
158         default:
159             *s++ = *r;
160         }
161         r++;
162     }
163     *s = '\0';
164     return(&name[0]);
165 }
This page took 0.053735 seconds and 5 git commands to generate.