]> andersk Git - moira.git/blame - clients/lib/utils.c
add a "version" argument to mrcl_connect
[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
4342cf40 24int mrcl_connect(char *server, char *client, int version, int auth)
013096e5 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
4342cf40 51 status = mr_version(version);
52 if (status)
53 {
54 if (status == MR_UNKNOWN_PROC)
55 {
56 if (version > 2)
57 status == MR_VERSION_HIGH;
58 else
59 status == MR_SUCCESS;
60 }
61
62 if (status == MR_VERSION_HIGH)
63 {
64 com_err(whoami, 0, "Warning: This client is running newer code than the server.");
65 com_err(whoami, 0, "Some operations may not work.");
66 }
67 else if (status != MR_VERSION_LOW)
68 {
69 com_err(whoami, status, "while setting query version number.");
70 mr_disconnect();
71 return MRCL_FAIL;
72 }
73 }
74
013096e5 75 if (auth)
76 {
77 status = mr_auth(client);
78 if (status)
79 {
80 com_err(whoami, status, "while authenticating to Moira.");
81 mr_disconnect();
82 return MRCL_AUTH_ERROR;
83 }
84 }
85
86 return MRCL_SUCCESS;
87}
88
89char *mrcl_krb_user(void)
90{
91 int status;
92 static char pname[ANAME_SZ];
93
94 status = tf_init(TKT_FILE, R_TKT_FIL);
95 if (status == KSUCCESS)
96 {
97 status = tf_get_pname(pname);
98 tf_close();
99 }
100
101 if (status != KSUCCESS)
102 {
103 /* In case mr_init hasn't been called yet. */
104 initialize_krb_error_table();
105 com_err(whoami, status, "reading Kerberos ticket file.");
106 return NULL;
107 }
108
109 return pname;
110}
This page took 0.091623 seconds and 5 git commands to generate.