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>
18 #include <sys/types.h>
21 #include <sys/utsname.h>
25 #include <sys/socket.h>
27 #include <netinet/in.h>
38 extern krb5_context context;
40 int mrcl_connect(char *server, char *client, int version, int auth)
45 status = mr_connect(server);
48 com_err(whoami, status, "while connecting to Moira");
52 status = mr_motd(&motd);
56 com_err(whoami, status, "while checking server status");
61 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
67 status = mr_version(version);
70 if (status == MR_UNKNOWN_PROC)
73 status = MR_VERSION_HIGH;
78 if (status == MR_VERSION_HIGH)
80 com_err(whoami, 0, "Warning: This client is running newer code than the server.");
81 com_err(whoami, 0, "Some operations may not work.");
83 else if (status && status != MR_VERSION_LOW)
85 com_err(whoami, status, "while setting query version number.");
93 status = mr_krb5_auth(client);
96 com_err(whoami, status, "while authenticating to Moira.");
98 return MRCL_AUTH_ERROR;
105 char *mrcl_krb_user(void)
108 krb5_ccache cache = NULL;
109 krb5_principal princ;
110 krb5_error_code status;
114 krb5_init_context(&context);
116 status = krb5_cc_default(context, &cache);
119 com_err(whoami, status, "while reading Kerberos ticket file.");
123 status = krb5_cc_get_principal(context, cache, &princ);
126 com_err(whoami, status, "while retrieving principal name.");
130 return (char *)krb5_princ_component(context, princ, 0);
134 char *partial_canonicalize_hostname(char *s)
137 static char *def_domain = NULL;
141 if (mr_host(buf, sizeof(buf)) == MR_SUCCESS)
143 cp = strchr(buf, '.');
145 def_domain = strdup(++cp);
153 hp = gethostbyname(name.nodename);
156 gethostname(name, sizeof(name));
157 name[sizeof(name)-1] = 0;
158 hp = gethostbyname(name);
159 #endif /* HAVE_UNAME */
160 cp = strchr(hp->h_name, '.');
162 def_domain = strdup(++cp);
168 if (strchr(s, '.') || strchr(s, '*'))
170 sprintf(buf, "%s.%s", s, def_domain);