rewrite to use get_default_username

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6316 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
1999-06-15 02:47:11 +00:00
parent 62bdd58c11
commit f67bbf1a82

View File

@@ -40,31 +40,17 @@
RCSID("$Id$"); RCSID("$Id$");
static char * /*
get_logname(void) * Try to find out what's a reasonable default principal.
{ */
char *p;
if((p = getenv("USER")))
return p;
if((p = getenv("LOGNAME")))
return p;
if((p = getenv("USERNAME")))
return p;
#if defined(HAVE_GETLOGIN) && !defined(POSIX_GETLOGIN)
if((p = getlogin()))
return p;
#endif
return NULL;
}
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)
{ {
krb5_error_code ret; krb5_error_code ret;
struct passwd *pw;
char *p;
krb5_ccache id; krb5_ccache id;
const char *user;
ret = krb5_cc_default (context, &id); ret = krb5_cc_default (context, &id);
if (ret == 0) { if (ret == 0) {
@@ -74,19 +60,13 @@ krb5_get_default_principal (krb5_context context,
return 0; return 0;
} }
pw = getpwuid(getuid()); user = get_default_username ();
if(pw == NULL) { if (user == NULL)
p = get_logname();
if(p == NULL)
return ENOTTY; return ENOTTY;
ret = krb5_make_principal(context, princ, NULL, p, NULL); if (getuid () == 0) {
ret = krb5_make_principal(context, princ, NULL, user, "root", NULL);
} else { } else {
if(strcmp(pw->pw_name, "root") == 0){ ret = krb5_make_principal(context, princ, NULL, user, NULL);
p = get_logname();
ret = krb5_make_principal(context, princ, NULL, pw->pw_name,
"root", NULL);
}else
ret = krb5_make_principal(context, princ, NULL, pw->pw_name, NULL);
} }
return ret; return ret;
} }