add a note about nsswitch.conf entry required for sudo-ldap
[debian/sudo] / find_path.c
index 124ad04a8947e44ddc33cf8c873ceb99f3f38164..22ff607df9562ce49c0d8d80c8b2c3638e5dd3c4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 1998-2004 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1996, 1998-2005 Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -18,7 +18,7 @@
  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
  */
 
-#include "config.h"
+#include <config.h>
 
 #include <sys/types.h>
 #include <sys/param.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif /* HAVE_UNISTD_H */
-#ifdef HAVE_ERR_H
-# include <err.h>
-#else
-# include "emul/err.h"
-#endif /* HAVE_ERR_H */
 
 #include "sudo.h"
 
-#ifndef lint
-static const char rcsid[] = "$Sudo: find_path.c,v 1.109 2004/08/24 18:01:12 millert Exp $";
-#endif /* lint */
-
 /*
  * This function finds the full pathname for a command and
  * stores it in a statically allocated array, filling in a pointer
@@ -76,7 +67,7 @@ find_path(infile, outfile, sbp, path)
     int len;                   /* length parameter */
 
     if (strlen(infile) >= PATH_MAX)
-       errx(1, "%s: File name too long", infile);
+       errorx(1, "%s: File name too long", infile);
 
     /*
      * If we were given a fully qualified or relative path
@@ -92,11 +83,9 @@ find_path(infile, outfile, sbp, path)
     }
 
     /* Use PATH passed in unless SECURE_PATH is in effect.  */
-#ifdef SECURE_PATH
-    if (!user_is_exempt())
-       path = SECURE_PATH;
-#endif /* SECURE_PATH */
-    if (path == NULL)
+    if (def_secure_path && !user_is_exempt())
+       path = def_secure_path;
+    else if (path == NULL)
        return(NOT_FOUND);
     path = estrdup(path);
     origpath = path;
@@ -120,20 +109,23 @@ find_path(infile, outfile, sbp, path)
         */
        len = snprintf(command, sizeof(command), "%s/%s", path, infile);
        if (len <= 0 || len >= sizeof(command))
-           errx(1, "%s: File name too long", infile);
+           errorx(1, "%s: File name too long", infile);
        if ((result = sudo_goodpath(command, sbp)))
            break;
 
        path = n + 1;
 
     } while (n);
-    free(origpath);
+    efree(origpath);
 
     /*
      * Check current dir if dot was in the PATH
      */
     if (!result && checkdot) {
-       result = sudo_goodpath(infile, sbp);
+       len = snprintf(command, sizeof(command), "./%s", infile);
+       if (len <= 0 || len >= sizeof(command))
+           errorx(1, "%s: File name too long", infile);
+       result = sudo_goodpath(command, sbp);
        if (result && def_ignore_dot)
            return(NOT_FOUND_DOT);
     }