#include <mrclient.h>
#include <com_err.h>
-#include <krb.h>
+#include <krb5.h>
#include <sys/types.h>
RCSID("$Header$");
extern char *whoami;
+extern krb5_context context;
int mrcl_connect(char *server, char *client, int version, int auth)
{
if (auth)
{
- status = mr_auth(client);
+ status = mr_krb5_auth(client);
+
+ /* New client talking to old server, try krb4. */
+ if (status == MR_UNKNOWN_PROC)
+ status = mr_auth(client);
+
if (status)
{
com_err(whoami, status, "while authenticating to Moira.");
char *mrcl_krb_user(void)
{
- int status;
- static char pname[ANAME_SZ];
+ int flags = 0;
+ krb5_ccache cache = NULL;
+ krb5_principal princ = NULL;
+ krb5_error_code status;
+ char *username = NULL;
+
+ if (!context)
+ krb5_init_context(&context);
- status = tf_init(TKT_FILE, R_TKT_FIL);
- if (status == KSUCCESS)
+ status = krb5_cc_default(context, &cache);
+ if (status)
{
- status = tf_get_pname(pname);
- tf_close();
+ com_err(whoami, status, "while reading Kerberos ticket file.");
+ goto out;
}
- if (status != KSUCCESS)
+ status = krb5_cc_get_principal(context, cache, &princ);
+ if (status)
{
- /* In case mr_init hasn't been called yet. */
- initialize_krb_error_table();
- status += ERROR_TABLE_BASE_krb;
- com_err(whoami, status, "reading Kerberos ticket file.");
- return NULL;
+ com_err(whoami, status, "while retrieving principal name.");
+ goto out;
}
- return pname;
+ username = malloc(krb5_princ_component(context, princ, 0)->length + 1);
+ if (!username)
+ goto out;
+
+ strncpy(username, krb5_princ_component(context, princ, 0)->data,
+ krb5_princ_component(context, princ, 0)->length);
+ username[krb5_princ_component(context, princ, 0)->length] = '\0';
+
+ out:
+ if (cache)
+ krb5_cc_close(context, cache);
+ if (princ)
+ krb5_free_principal(context, princ);
+
+ return username;
}
char *partial_canonicalize_hostname(char *s)