]> andersk Git - moira.git/blame - clients/lib/utils.c
mr_version()
[moira.git] / clients / lib / utils.c
CommitLineData
013096e5 1/* $Id$
2 *
3 * Random client utilities.
4 *
5 * Copyright (C) 1999 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 <mrclient.h>
13
14#include <stdlib.h>
15#include <stdio.h>
16
17#include <com_err.h>
18#include <krb.h>
19
20RCSID("$Header$");
21
22extern char *whoami;
23
24int mrcl_connect(char *server, char *client, int auth)
25{
26 int status;
27 char *motd;
28
29 status = mr_connect(server);
30 if (status)
31 {
32 com_err(whoami, status, "while connecting to Moira");
33 return MRCL_FAIL;
34 }
35
36 status = mr_motd(&motd);
37 if (status)
38 {
39 mr_disconnect();
40 com_err(whoami, status, "while checking server status");
41 return MRCL_FAIL;
42 }
43 if (motd)
44 {
45 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
46 motd);
47 mr_disconnect();
48 return MRCL_FAIL;
49 }
50
51 if (auth)
52 {
53 status = mr_auth(client);
54 if (status)
55 {
56 com_err(whoami, status, "while authenticating to Moira.");
57 mr_disconnect();
58 return MRCL_AUTH_ERROR;
59 }
60 }
61
62 return MRCL_SUCCESS;
63}
64
65char *mrcl_krb_user(void)
66{
67 int status;
68 static char pname[ANAME_SZ];
69
70 status = tf_init(TKT_FILE, R_TKT_FIL);
71 if (status == KSUCCESS)
72 {
73 status = tf_get_pname(pname);
74 tf_close();
75 }
76
77 if (status != KSUCCESS)
78 {
79 /* In case mr_init hasn't been called yet. */
80 initialize_krb_error_table();
81 com_err(whoami, status, "reading Kerberos ticket file.");
82 return NULL;
83 }
84
85 return pname;
86}
This page took 0.204926 seconds and 5 git commands to generate.