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,53 +40,33 @@
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) {
ret = krb5_cc_get_principal(context, id, princ); ret = krb5_cc_get_principal (context, id, princ);
krb5_cc_close(context, id); krb5_cc_close (context, id);
if(ret == 0) if (ret == 0)
return 0; return 0;
} }
pw = getpwuid(getuid()); user = get_default_username ();
if(pw == NULL) { if (user == NULL)
p = get_logname(); return ENOTTY;
if(p == NULL) if (getuid () == 0) {
return ENOTTY; ret = krb5_make_principal(context, princ, NULL, user, "root", NULL);
ret = krb5_make_principal(context, princ, NULL, p, NULL); } else {
}else{ ret = krb5_make_principal(context, princ, NULL, user, NULL);
if(strcmp(pw->pw_name, "root") == 0){
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;
} }