3 * Random client utilities.
5 * Copyright (C) 1999 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
17 #include <sys/types.h>
20 #include <sys/utsname.h>
24 #include <sys/socket.h>
26 #include <netinet/in.h>
38 int mrcl_connect(char *server, char *client, int version, int auth)
43 status = mr_connect(server);
46 com_err(whoami, status, "while connecting to Moira");
50 status = mr_motd(&motd);
54 com_err(whoami, status, "while checking server status");
59 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
65 status = mr_version(version);
68 if (status == MR_UNKNOWN_PROC)
71 status = MR_VERSION_HIGH;
76 if (status == MR_VERSION_HIGH)
78 com_err(whoami, 0, "Warning: This client is running newer code than the server.");
79 com_err(whoami, 0, "Some operations may not work.");
81 else if (status && status != MR_VERSION_LOW)
83 com_err(whoami, status, "while setting query version number.");
91 status = mr_auth(client);
94 com_err(whoami, status, "while authenticating to Moira.");
96 return MRCL_AUTH_ERROR;
103 char *mrcl_krb_user(void)
106 static char pname[ANAME_SZ];
108 status = tf_init(TKT_FILE, R_TKT_FIL);
109 if (status == KSUCCESS)
111 status = tf_get_pname(pname);
115 if (status != KSUCCESS)
117 /* In case mr_init hasn't been called yet. */
118 initialize_krb_error_table();
119 status += ERROR_TABLE_BASE_krb;
120 com_err(whoami, status, "reading Kerberos ticket file.");
127 char *partial_canonicalize_hostname(char *s)
130 static char *def_domain = NULL;
134 if (mr_host(buf, sizeof(buf)) == MR_SUCCESS)
136 cp = strchr(buf, '.');
138 def_domain = strdup(++cp);
146 hp = gethostbyname(name.nodename);
149 gethostname(name, sizeof(name));
150 name[sizeof(name)-1] = 0;
151 hp = gethostbyname(name);
152 #endif /* HAVE_UNAME */
153 cp = strchr(hp->h_name, '.');
155 def_domain = strdup(++cp);
161 if (strchr(s, '.') || strchr(s, '*'))
163 sprintf(buf, "%s.%s", s, def_domain);