change this slightly

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@9831 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2001-05-02 09:04:38 +00:00
parent 25ad02d691
commit b7a0cebddc

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997 - 1999 Kungliga Tekniska H<>gskolan * Copyright (c) 1997 - 1999, 2001 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden). * (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved. * All rights reserved.
* *
@@ -39,6 +39,17 @@ RCSID("$Id$");
* Try to find out what's a reasonable default principal. * Try to find out what's a reasonable default principal.
*/ */
static const char*
get_env_user(void)
{
const char *user = getenv("USER");
if(user == NULL)
user = getenv("LOGNAME");
if(user == NULL)
user = getenv("USERNAME");
return user;
}
krb5_error_code krb5_error_code
krb5_get_default_principal (krb5_context context, krb5_get_default_principal (krb5_context context,
krb5_principal *princ) krb5_principal *princ)
@@ -46,6 +57,7 @@ krb5_get_default_principal (krb5_context context,
krb5_error_code ret; krb5_error_code ret;
krb5_ccache id; krb5_ccache id;
const char *user; const char *user;
uid_t uid;
ret = krb5_cc_default (context, &id); ret = krb5_cc_default (context, &id);
if (ret == 0) { if (ret == 0) {
@@ -55,13 +67,29 @@ krb5_get_default_principal (krb5_context context,
return 0; return 0;
} }
user = get_default_username ();
if (user == NULL) uid = getuid();
return ENOTTY; if(uid == 0) {
if (getuid () == 0) { user = getlogin();
ret = krb5_make_principal(context, princ, NULL, user, "root", NULL); if(user == NULL)
user = get_env_user();
if(user != NULL && strcmp(user, "root") != 0)
ret = krb5_make_principal(context, princ, NULL, user, "root", NULL);
else
ret = krb5_make_principal(context, princ, NULL, "root", NULL);
} else { } else {
struct passwd *pw = getpwuid(uid);
if(pw != NULL)
user = pw->pw_name;
else {
user = get_env_user();
if(user == NULL)
user = getlogin();
}
if(user == NULL)
return ENOTTY; /* XXX */
ret = krb5_make_principal(context, princ, NULL, user, NULL); ret = krb5_make_principal(context, princ, NULL, user, NULL);
} }
return ret; return ret;
} }