]> andersk Git - moira.git/blob - lib/mr_auth.c
aabd780de7b47fd090ca460fc44b28748165e845
[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 <string.h>
16
17 #include <krb.h>
18
19 RCSID("$Header$");
20
21 /* Authenticate this client with the Moira server.  prog is the name of the
22  * client program, and will be recorded in the database.
23  */
24
25 int mr_auth(char *prog)
26 {
27   int status;
28   mr_params params_st;
29   char *args[2];
30   int argl[2];
31   char realm[REALM_SZ], host[BUFSIZ], *p;
32   mr_params *params = &params_st;
33   mr_params *reply = NULL;
34   KTEXT_ST auth;
35
36   CHECK_CONNECTED;
37
38   /* Build a Kerberos authenticator. */
39
40   memset(host, 0, sizeof(host));
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->mr_version_no = sending_version_no;
59   params->mr_procno = MR_AUTH;
60   params->mr_argc = 2;
61   params->mr_argv = args;
62   params->mr_argl = argl;
63   params->mr_argv[0] = (char *)auth.dat;
64   params->mr_argl[0] = auth.length;
65   params->mr_argv[1] = prog;
66   params->mr_argl[1] = strlen(prog) + 1;
67
68   if (sending_version_no == MR_VERSION_1)
69     params->mr_argc = 1;
70
71   if ((status = mr_do_call(params, &reply)) == 0)
72     status = reply->mr_status;
73
74   mr_destroy_reply(reply);
75
76   return status;
77 }
This page took 0.647519 seconds and 3 git commands to generate.