diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2012-06-07 20:20:25 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2012-06-07 20:20:25 +0000 |
commit | 6a69937862dae0dcad84f30dbe32767c5a3eb149 (patch) | |
tree | 53557e77ac2b3ab2cc0dd8939331aa8b7b27017d /app/xterm/xstrings.c | |
parent | a64d53a3cd043209550978ba9e9b8d5c21725516 (diff) |
Update to xterm 279. Tested by krw@, mpi@, shadchin@.
Diffstat (limited to 'app/xterm/xstrings.c')
-rw-r--r-- | app/xterm/xstrings.c | 89 |
1 files changed, 49 insertions, 40 deletions
diff --git a/app/xterm/xstrings.c b/app/xterm/xstrings.c index 5fe083536..395def5ab 100644 --- a/app/xterm/xstrings.c +++ b/app/xterm/xstrings.c @@ -1,7 +1,7 @@ -/* $XTermId: xstrings.c,v 1.47 2011/09/11 20:20:12 tom Exp $ */ +/* $XTermId: xstrings.c,v 1.50 2012/03/30 10:54:12 tom Exp $ */ /* - * Copyright 2000-2010,2011 by Thomas E. Dickey + * Copyright 2000-2011,2012 by Thomas E. Dickey * * All Rights Reserved * @@ -141,42 +141,21 @@ x_encode_hex(const char *source) char * x_getenv(const char *name) { - return x_strdup(x_nonempty(getenv(name))); + char *result; + result = x_strdup(x_nonempty(getenv(name))); + TRACE2(("getenv(%s) %s\n", name, result)); + return result; } -/* - * Call this with in_out pointing to data filled in by x_getpwnam() or by - * x_getpwnam(). It finds the user's logon name, if possible. As a side - * effect, it updates in_out to fill in possibly more-relevant data, i.e., - * in case there is more than one alias for the same uid. - */ -char * -x_getlogin(uid_t uid, struct passwd *in_out) +static char * +login_alias(char *login_name, uid_t uid, struct passwd *in_out) { - char *login_name = NULL; - -#ifdef HAVE_GETLOGIN - login_name = getlogin(); -#endif - - /* - * Of course getlogin() will fail if we're started from a window-manager, - * since there's no controlling terminal to fuss with. In that case, try - * to get something useful from the user's $LOGNAME or $USER environment - * variables. - */ - if (login_name == NULL) { - login_name = x_getenv("LOGNAME"); - if (login_name == NULL) - login_name = x_getenv("USER"); - } - /* * If the logon-name differs from the value we get by looking in the * password file, check if it does correspond to the same uid. If so, * allow that as an alias for the uid. */ - if (login_name != NULL + if (!IsEmpty(login_name) && strcmp(login_name, in_out->pw_name)) { struct passwd pw2; @@ -184,23 +163,52 @@ x_getlogin(uid_t uid, struct passwd *in_out) uid_t uid2 = pw2.pw_uid; struct passwd pw3; - if (!x_getpwuid(uid, &pw3) - || (uid_t) pw3.pw_uid != uid2) { - login_name = NULL; - } else { + if (x_getpwuid(uid, &pw3) + && ((uid_t) pw3.pw_uid == uid2)) { /* use the other passwd-data including shell */ alloc_pw(in_out, &pw2); + } else { + login_name = NULL; } - } else { - (void) x_getpwuid(uid, in_out); } } + return login_name; +} + +/* + * Call this with in_out pointing to data filled in by x_getpwnam() or by + * x_getpwnam(). It finds the user's logon name, if possible. As a side + * effect, it updates in_out to fill in possibly more-relevant data, i.e., + * in case there is more than one alias for the same uid. + */ +char * +x_getlogin(uid_t uid, struct passwd *in_out) +{ + char *login_name = NULL; + + login_name = login_alias(x_getenv("LOGNAME"), uid, in_out); + if (IsEmpty(login_name)) { + login_name = login_alias(x_getenv("USER"), uid, in_out); + } +#ifdef HAVE_GETLOGIN + /* + * Of course getlogin() will fail if we're started from a window-manager, + * since there's no controlling terminal to fuss with. For that reason, we + * tried first to get something useful from the user's $LOGNAME or $USER + * environment variables. + */ + if (IsEmpty(login_name)) { + TRACE2(("...try getlogin\n")); + login_name = login_alias(getlogin(), uid, in_out); + } +#endif - if (login_name == NULL) + if (IsEmpty(login_name)) login_name = in_out->pw_name; - if (login_name != NULL) + if (!IsEmpty(login_name)) login_name = x_strdup(login_name); + TRACE2(("x_getloginid ->%s\n", NonNull(login_name))); return login_name; } @@ -214,7 +222,7 @@ x_getpwnam(const char *name, struct passwd * result) struct passwd *ptr = getpwnam(name); Boolean code; - if (OkPasswd(ptr)) { + if (ptr != 0 && OkPasswd(ptr)) { code = True; alloc_pw(result, ptr); } else { @@ -234,13 +242,14 @@ x_getpwuid(uid_t uid, struct passwd * result) struct passwd *ptr = getpwuid((uid_t) uid); Boolean code; - if (OkPasswd(ptr)) { + if (ptr != 0 && OkPasswd(ptr)) { code = True; alloc_pw(result, ptr); } else { code = False; memset(result, 0, sizeof(*result)); } + TRACE2(("x_getpwuid(%d) %d\n", (int) uid, (int) code)); return code; } |