]> andersk Git - moira.git/blob - lib/mr_auth.c
Don't truncate FQDN we got back from mr_host in the krb5 auth case.
[moira.git] / lib / mr_auth.c
1 /* $Id$
2  *
3  * Handles the client side of the sending of authenticators to the moira server
4  *
5  * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
6  * For copying and distribution information, please see the file
7  * <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <moira.h>
12 #include "mr_private.h"
13
14 #include <ctype.h>
15 #include <stdio.h>
16 #include <string.h>
17
18 #include <krb.h>
19 #include <krb5.h>
20
21 krb5_context context = NULL;
22 krb5_auth_context auth_con = NULL;
23
24 RCSID("$Header$");
25
26 /* Authenticate this client with the Moira server.  prog is the name of the
27  * client program, and will be recorded in the database.
28  */
29
30 int mr_auth(char *prog)
31 {
32   int status;
33   mr_params params, reply;
34   char *args[2];
35   int argl[2];
36   char realm[REALM_SZ], host[BUFSIZ], *p;
37   KTEXT_ST auth;
38
39   CHECK_CONNECTED;
40
41   if ((status = mr_host(host, sizeof(host) - 1)))
42     return status;
43
44   strcpy(realm, krb_realmofhost(host));
45   for (p = host; *p && *p != '.'; p++)
46     {
47       if (isupper(*p))
48         *p = tolower(*p);
49     }
50   *p = '\0';
51
52   status = krb_mk_req(&auth, MOIRA_SNAME, host, realm, 0);
53   if (status != KSUCCESS)
54     {
55       status += ERROR_TABLE_BASE_krb;
56       return status;
57     }
58   params.u.mr_procno = MR_AUTH;
59   params.mr_argc = 2;
60   params.mr_argv = args;
61   params.mr_argl = argl;
62   params.mr_argv[0] = (char *)auth.dat;
63   params.mr_argl[0] = auth.length;
64   params.mr_argv[1] = prog;
65   params.mr_argl[1] = strlen(prog) + 1;
66
67   if ((status = mr_do_call(&params, &reply)) == MR_SUCCESS)
68     status = reply.u.mr_status;
69
70   mr_destroy_reply(reply);
71
72   return status;
73 }
74
75 int mr_proxy(char *principal, char *orig_authtype)
76 {
77   int status;
78   mr_params params, reply;
79   char *args[2];
80
81   params.u.mr_procno = MR_PROXY;
82   params.mr_argc = 2;
83   params.mr_argv = args;
84   params.mr_argv[0] = principal;
85   params.mr_argv[1] = orig_authtype;
86   params.mr_argl = NULL;
87
88   if ((status = mr_do_call(&params, &reply)) == MR_SUCCESS)
89     status = reply.u.mr_status;
90
91   mr_destroy_reply(reply);
92
93   return status;
94 }
95
96 int mr_krb5_auth(char *prog)
97 {
98   mr_params params, reply;
99   char host[BUFSIZ], *p;
100   char *args[2];
101   int argl[2];
102   krb5_ccache ccache = NULL;
103   krb5_data auth;
104   krb5_error_code problem = 0;
105
106   CHECK_CONNECTED;
107
108   memset(&auth, 0, sizeof(auth));
109
110   if ((problem = mr_host(host, sizeof(host) - 1)))
111     return problem;
112
113   if (!context)
114     {
115       problem = krb5_init_context(&context);
116       if (problem)
117         goto out;
118     }
119
120   problem = krb5_auth_con_init(context, &auth_con);
121   if (problem)
122     goto out;
123
124   problem = krb5_cc_default(context, &ccache);
125   if (problem)
126     goto out;
127
128   problem = krb5_mk_req(context, &auth_con, NULL, MOIRA_SNAME, host, NULL, 
129                        ccache, &auth);
130   if (problem)
131     goto out;
132
133   params.u.mr_procno = MR_KRB5_AUTH;
134   params.mr_argc = 2;
135   params.mr_argv = args;
136   params.mr_argl = argl;
137   params.mr_argv[0] = (char *)auth.data;
138   params.mr_argl[0] = auth.length;
139   params.mr_argv[1] = prog;
140   params.mr_argl[1] = strlen(prog) + 1;
141
142   if ((problem = mr_do_call(&params, &reply)) == MR_SUCCESS)
143     problem = reply.u.mr_status;
144
145   mr_destroy_reply(reply);
146
147  out:
148   if (ccache)
149     krb5_cc_close(context, ccache);
150   krb5_free_data_contents(context, &auth);
151   if (auth_con)
152     krb5_auth_con_free(context, auth_con);
153   auth_con = NULL;
154
155   return problem;
156 }
157       
This page took 0.054704 seconds and 5 git commands to generate.