845 {
846 struct stat stb;
847 if (stat(file, &stb) < 0) {
848 return ( -1);
849 }
850 if (S_ISDIR(stb.st_mode)) {
851 return (-1);
852 }
853 if (!(stb.st_mode & S_IEXEC)) {
854 return ( -1);
855 }
856 return (0);
857 }
858
859 /* resolve - check for specified file in specified directory
860 * sets up dir, following symlinks.
861 * returns zero for success, or
862 * -1 for error (with errno set properly)
863 */
864 static int
865 resolve (char *indir, /* search directory */
866 char *cmd, /* search for name */
867 char *dir, /* directory buffer */
868 char **run) /* resultion name ptr ptr */
869 {
870 char *p;
871 int rv = -1;
872 int sll;
873 char symlink[MAXPATHLEN + 1];
874
875 do {
876 errno = ENAMETOOLONG;
877 if ((strlen (indir) + strlen (cmd) + 2) > (size_t) MAXPATHLEN)
878 break;
879
880 sprintf(dir, "%s/%s", indir, cmd);
881 if (check_if_exec(dir) != 0) /* check if dir is an executable */
882 {
883 break; /* Not an executable program */
884 }
885
886 /* follow symbolic links */
|
845 {
846 struct stat stb;
847 if (stat(file, &stb) < 0) {
848 return ( -1);
849 }
850 if (S_ISDIR(stb.st_mode)) {
851 return (-1);
852 }
853 if (!(stb.st_mode & S_IEXEC)) {
854 return ( -1);
855 }
856 return (0);
857 }
858
859 /* resolve - check for specified file in specified directory
860 * sets up dir, following symlinks.
861 * returns zero for success, or
862 * -1 for error (with errno set properly)
863 */
864 static int
865 resolve (const char *indir, /* search directory */
866 const char *cmd, /* search for name */
867 char *dir, /* directory buffer */
868 char **run) /* resultion name ptr ptr */
869 {
870 char *p;
871 int rv = -1;
872 int sll;
873 char symlink[MAXPATHLEN + 1];
874
875 do {
876 errno = ENAMETOOLONG;
877 if ((strlen (indir) + strlen (cmd) + 2) > (size_t) MAXPATHLEN)
878 break;
879
880 sprintf(dir, "%s/%s", indir, cmd);
881 if (check_if_exec(dir) != 0) /* check if dir is an executable */
882 {
883 break; /* Not an executable program */
884 }
885
886 /* follow symbolic links */
|