#! /bin/sh /usr/share/dpatch/dpatch-run ## hesiod.dpatch by Anders Kaseorg ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Changes to Hesiod-based ~ expansion; from Athena 9.4 tcsh. @DPATCH@ --- tcsh-6.14.00.orig/tc.func.c 2005-03-05 22:57:10.000000000 -0500 +++ tcsh-6.14.00/tc.func.c 2005-06-09 12:00:31.000000000 -0400 @@ -1569,41 +1569,43 @@ return Strcmp(p1->user, p2->user); } +#ifdef HESIOD static Char * -gethomedir(us) - Char *us; +hes_gethomedir(us) + Char *us; { - struct passwd *pp; -#ifdef HESIOD char **res, **res1, *cp; Char *rp; -#endif /* HESIOD */ - - pp = getpwnam(short2str(us)); -#ifdef YPBUGS - fix_yp_bugs(); -#endif /* YPBUGS */ - if (pp != NULL) { -#if 0 - /* Don't return if root */ - if (pp->pw_dir[0] == '/' && pp->pw_dir[1] == '\0') - return NULL; - else -#endif - return Strsave(str2short(pp->pw_dir)); - } -#ifdef HESIOD + int which; + res = hes_resolve(short2str(us), "filsys"); rp = NULL; if (res != NULL) { if ((*res) != NULL) { + int i, lowest, new; + + /* Use the first filesys if there's an ordered list */ + lowest = -1; + which = 0; + if (res[1]) { + for (i = 0; res[i]; i++) { + cp = strrchr(res[i], ' '); + if (!cp) + return NULL; + new = atoi(cp + 1); + if (lowest == -1 || new < lowest) { + lowest = new; + which = i; + } + } + } /* * Look at the first token to determine how to interpret * the rest of it. * Yes, strtok is evil (it's not thread-safe), but it's also * easy to use. */ - cp = strtok(*res, " "); + cp = strtok(res[which], " "); if (strcmp(cp, "AFS") == 0) { /* next token is AFS pathname.. */ cp = strtok(NULL, " "); @@ -1630,8 +1632,33 @@ #endif return rp; } + return NULL; +} #endif /* HESIOD */ + +static Char * +gethomedir(us) + Char *us; +{ + register struct passwd *pp; + +#ifdef HESIOD + /* Always do Hesiod filsys lookup on ~~username. */ + if (*us == '~') + return hes_gethomedir(us + 1); +#endif + pp = getpwnam(short2str(us)); +#ifdef YPBUGS + fix_yp_bugs(); +#endif /* YPBUGS */ + if (pp != NULL) + return Strsave(str2short(pp->pw_dir)); +#ifdef HESIOD + /* Fall back to Hesiod lookup on ~username if passwd lookup fails. */ + return hes_gethomedir(us); +#else /* HESIOD */ return NULL; +#endif /* HESIOD */ } Char *