]> andersk Git - moira.git/blame - server/mr_sauth.c
missing stubs
[moira.git] / server / mr_sauth.c
CommitLineData
a3cf6921 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
c801de4c 7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
a3cf6921 9 *
a3cf6921 10 */
11
12#ifndef lint
13static char *rcsid_sms_sauth_c = "$Header$";
14#endif lint
15
c801de4c 16#include <mit-copyright.h>
a3cf6921 17#include <strings.h>
d548a4e7 18#include "mr_server.h"
713cf9c9 19#include <ctype.h>
40165bd0 20#include <krb_et.h>
a3cf6921 21
22extern char buf1[];
23extern char *whoami;
24extern char *malloc();
25
c1665e6d 26char *kname_unparse();
27
a3cf6921 28/*
d548a4e7 29 * Handle a MOIRA_AUTH RPC request.
a3cf6921 30 *
31 * argv[0] is a kerberos authenticator. Decompose it, and if
32 * successful, store the name the user authenticated to in
33 * cl->cl_name.
34 */
35
36void
37do_auth(cl)
38 client *cl;
39{
40 KTEXT_ST auth;
41 AUTH_DAT ad;
c1665e6d 42 int status, ok;
713cf9c9 43 char buf[REALM_SZ+INST_SZ+ANAME_SZ], hostbuf[BUFSIZ], *host, *p;
a53c9c79 44 extern int errno;
713cf9c9 45
d548a4e7 46 auth.length = cl->args->mr_argl[0];
47 bcopy(cl->args->mr_argv[0], (char *)auth.dat, auth.length);
a3cf6921 48 auth.mbz = 0;
713cf9c9 49 if (gethostname(hostbuf, sizeof(hostbuf)) < 0)
50 com_err(whoami, errno, "Unable to get local hostname");
51 host = canonicalize_hostname(strsave(hostbuf));
52 for (p = host; *p && *p != '.'; p++)
53 if (isupper(*p))
54 *p = tolower(*p);
55 *p = 0;
56
57 if ((status = krb_rd_req (&auth, MOIRA_SNAME, host, cl->haddr.sin_addr,
9b612b77 58 &ad, "")) != 0 &&
59 /* for backwards compatability with old clients */
60 (status = krb_rd_req (&auth, "sms", "sms", cl->haddr.sin_addr,
40165bd0 61 &ad, "")) != 0) {
62 status += ERROR_TABLE_BASE_krb;
d548a4e7 63 cl->reply.mr_status = status;
060e9c63 64 if (log_flags & LOG_RES)
65 com_err(whoami, status, "(authentication failed)");
a3cf6921 66 return;
67 }
713cf9c9 68 free(host);
c1665e6d 69
8a36ddfe 70 bcopy(ad.pname, cl->kname.name, ANAME_SZ);
71 bcopy(ad.pinst, cl->kname.inst, INST_SZ);
72 bcopy(ad.prealm, cl->kname.realm, REALM_SZ);
c1665e6d 73 strcpy(cl->clname, kname_unparse(ad.pname, ad.pinst, ad.prealm));
90021a6f 74
c1665e6d 75 if (ad.pinst[0] == 0 && !strcmp(ad.prealm, krb_realm))
76 ok = 1;
77 else
78 ok = 0;
79 /* this is in a separate function because it accesses the database */
aa3c5c98 80 status = set_krb_mapping(cl->clname, ad.pname, ok,
81 &cl->client_id, &cl->users_id);
90021a6f 82
d548a4e7 83 if (cl->args->mr_version_no == MR_VERSION_2) {
84 bcopy(cl->args->mr_argv[1], cl->entity, 8);
c1665e6d 85 cl->entity[8] = 0;
90021a6f 86 } else {
c1665e6d 87 strcpy(cl->entity, "???");
060e9c63 88 }
c0d41186 89 bzero(&ad, sizeof(ad)); /* Clean up session key, etc. */
90021a6f 90
91 if (log_flags & LOG_RES)
c1665e6d 92 com_err(whoami, 0, "Auth to %s using %s, uid %d cid %d",
93 cl->clname, cl->entity, cl->users_id, cl->client_id);
aa3c5c98 94 if (status != MR_SUCCESS)
95 cl->reply.mr_status = status;
96 else if (cl->users_id == 0)
d548a4e7 97 cl->reply.mr_status = MR_USER_AUTH;
a3cf6921 98}
c1665e6d 99
100
101/* Turn a principal, instance, realm triple into a single non-ambiguous
102 * string. This is the inverse of kname_parse(). It returns a pointer
103 * to a static buffer, or NULL on error.
104 */
105
106char *kname_unparse(p, i, r)
107char *p;
108char *i;
109char *r;
110{
111 static char name[MAX_K_NAME_SZ];
112 char *s;
113
114 s = name;
115 if (!p || strlen(p) > ANAME_SZ)
116 return(NULL);
117 while (*p) {
118 switch (*p) {
119 case '@':
120 *s++ = '\\';
121 *s++ = '@';
122 break;
123 case '.':
124 *s++ = '\\';
125 *s++ = '.';
126 break;
127 case '\\':
128 *s++ = '\\';
129 *s++ = '\\';
130 break;
131 default:
132 *s++ = *p;
133 }
134 p++;
135 }
136 if (i && *i) {
137 if (strlen(i) > INST_SZ)
138 return(NULL);
139 *s++ = '.';
140 while (*i) {
141 switch (*i) {
142 case '@':
143 *s++ = '\\';
144 *s++ = '@';
145 break;
146 case '.':
147 *s++ = '\\';
148 *s++ = '.';
149 break;
150 case '\\':
151 *s++ = '\\';
152 *s++ = '\\';
153 break;
154 default:
155 *s++ = *i;
156 }
157 i++;
158 }
159 }
160 *s++ = '@';
161 if (!r || strlen(r) > REALM_SZ)
162 return(NULL);
163 while (*r) {
164 switch (*r) {
165 case '@':
166 *s++ = '\\';
167 *s++ = '@';
168 break;
169 case '\\':
170 *s++ = '\\';
171 *s++ = '\\';
172 break;
173 default:
174 *s++ = *r;
175 }
176 r++;
177 }
178 *s = '\0';
179 return(&name[0]);
180}
This page took 0.366579 seconds and 5 git commands to generate.