[22698] | 1 | #! /bin/sh /usr/share/dpatch/dpatch-run |
---|
| 2 | ## hesiod.dpatch by Anders Kaseorg <andersk@mit.edu> |
---|
| 3 | ## |
---|
| 4 | ## All lines beginning with `## DP:' are a description of the patch. |
---|
| 5 | ## DP: Changes to Hesiod-based ~ expansion; from Athena 9.4 tcsh. |
---|
| 6 | |
---|
| 7 | @DPATCH@ |
---|
| 8 | |
---|
| 9 | --- tcsh-6.14.00.orig/tc.func.c 2005-03-05 22:57:10.000000000 -0500 |
---|
| 10 | +++ tcsh-6.14.00/tc.func.c 2005-06-09 12:00:31.000000000 -0400 |
---|
| 11 | @@ -1569,41 +1569,43 @@ |
---|
| 12 | return Strcmp(p1->user, p2->user); |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | +#ifdef HESIOD |
---|
| 16 | static Char * |
---|
| 17 | -gethomedir(us) |
---|
| 18 | - Char *us; |
---|
| 19 | +hes_gethomedir(us) |
---|
| 20 | + Char *us; |
---|
| 21 | { |
---|
| 22 | - struct passwd *pp; |
---|
| 23 | -#ifdef HESIOD |
---|
| 24 | char **res, **res1, *cp; |
---|
| 25 | Char *rp; |
---|
| 26 | -#endif /* HESIOD */ |
---|
| 27 | - |
---|
| 28 | - pp = getpwnam(short2str(us)); |
---|
| 29 | -#ifdef YPBUGS |
---|
| 30 | - fix_yp_bugs(); |
---|
| 31 | -#endif /* YPBUGS */ |
---|
| 32 | - if (pp != NULL) { |
---|
| 33 | -#if 0 |
---|
| 34 | - /* Don't return if root */ |
---|
| 35 | - if (pp->pw_dir[0] == '/' && pp->pw_dir[1] == '\0') |
---|
| 36 | - return NULL; |
---|
| 37 | - else |
---|
| 38 | -#endif |
---|
| 39 | - return Strsave(str2short(pp->pw_dir)); |
---|
| 40 | - } |
---|
| 41 | -#ifdef HESIOD |
---|
| 42 | + int which; |
---|
| 43 | + |
---|
| 44 | res = hes_resolve(short2str(us), "filsys"); |
---|
| 45 | rp = NULL; |
---|
| 46 | if (res != NULL) { |
---|
| 47 | if ((*res) != NULL) { |
---|
| 48 | + int i, lowest, new; |
---|
| 49 | + |
---|
| 50 | + /* Use the first filesys if there's an ordered list */ |
---|
| 51 | + lowest = -1; |
---|
| 52 | + which = 0; |
---|
| 53 | + if (res[1]) { |
---|
| 54 | + for (i = 0; res[i]; i++) { |
---|
| 55 | + cp = strrchr(res[i], ' '); |
---|
| 56 | + if (!cp) |
---|
| 57 | + return NULL; |
---|
| 58 | + new = atoi(cp + 1); |
---|
| 59 | + if (lowest == -1 || new < lowest) { |
---|
| 60 | + lowest = new; |
---|
| 61 | + which = i; |
---|
| 62 | + } |
---|
| 63 | + } |
---|
| 64 | + } |
---|
| 65 | /* |
---|
| 66 | * Look at the first token to determine how to interpret |
---|
| 67 | * the rest of it. |
---|
| 68 | * Yes, strtok is evil (it's not thread-safe), but it's also |
---|
| 69 | * easy to use. |
---|
| 70 | */ |
---|
| 71 | - cp = strtok(*res, " "); |
---|
| 72 | + cp = strtok(res[which], " "); |
---|
| 73 | if (strcmp(cp, "AFS") == 0) { |
---|
| 74 | /* next token is AFS pathname.. */ |
---|
| 75 | cp = strtok(NULL, " "); |
---|
| 76 | @@ -1630,8 +1632,33 @@ |
---|
| 77 | #endif |
---|
| 78 | return rp; |
---|
| 79 | } |
---|
| 80 | + return NULL; |
---|
| 81 | +} |
---|
| 82 | #endif /* HESIOD */ |
---|
| 83 | + |
---|
| 84 | +static Char * |
---|
| 85 | +gethomedir(us) |
---|
| 86 | + Char *us; |
---|
| 87 | +{ |
---|
| 88 | + register struct passwd *pp; |
---|
| 89 | + |
---|
| 90 | +#ifdef HESIOD |
---|
| 91 | + /* Always do Hesiod filsys lookup on ~~username. */ |
---|
| 92 | + if (*us == '~') |
---|
| 93 | + return hes_gethomedir(us + 1); |
---|
| 94 | +#endif |
---|
| 95 | + pp = getpwnam(short2str(us)); |
---|
| 96 | +#ifdef YPBUGS |
---|
| 97 | + fix_yp_bugs(); |
---|
| 98 | +#endif /* YPBUGS */ |
---|
| 99 | + if (pp != NULL) |
---|
| 100 | + return Strsave(str2short(pp->pw_dir)); |
---|
| 101 | +#ifdef HESIOD |
---|
| 102 | + /* Fall back to Hesiod lookup on ~username if passwd lookup fails. */ |
---|
| 103 | + return hes_gethomedir(us); |
---|
| 104 | +#else /* HESIOD */ |
---|
| 105 | return NULL; |
---|
| 106 | +#endif /* HESIOD */ |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | Char * |
---|