]> granicus.if.org Git - sudo/commitdiff
regen
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 21 Feb 2009 21:51:42 +0000 (21:51 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 21 Feb 2009 21:51:42 +0000 (21:51 +0000)
toke.c

diff --git a/toke.c b/toke.c
index 0c913166ec5e4480050e0a6eab2d2508cc0ef51f..6442bfa2339d351093631297a15cf15515d565cf 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -3258,22 +3258,43 @@ parse_include(base)
     char *base;
 {
     char *cp, *ep, *path;
-    int len;
+    int len = 0, subst = 0;
+    size_t shost_len = 0;
 
     /* Pull out path from #include line. */
     cp = base + sizeof("#include");
     while (isblank((unsigned char) *cp))
        cp++;
     ep = cp;
-    while (*ep != '\0' && !isspace((unsigned char) *ep))
+    while (*ep != '\0' && !isspace((unsigned char) *ep)) {
+       if (ep[0] == '%' && ep[1] == 'h') {
+           shost_len = strlen(user_shost);
+           len += shost_len - 2;
+           subst = 1;
+       }
        ep++;
+    }
 
     /* Make a copy of path and return it. */
-    len = (int)(ep - cp);
+    len += (int)(ep - cp);
     if ((path = malloc(len + 1)) == NULL)
        yyerror("unable to allocate memory");
-    memcpy(path, cp, len);
-    path[len] = '\0';
+    if (subst) {
+       /* substitute for %h */
+       char *pp = path;
+       while (cp < ep) {
+           if (cp[0] == '%' && cp[1] == 'h') {
+               memcpy(pp, user_shost, shost_len);
+               pp += shost_len;
+               cp += 2;
+           }
+           *pp++ = *cp++;
+       }
+       *pp = '\0';
+    } else {
+       memcpy(path, cp, len);
+       path[len] = '\0';
+    }
 
     /* Push any excess characters (e.g. comment, newline) back to the lexer */
     if (*ep != '\0')