[BACK]Return to goodpath.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / sudo

Annotation of src/usr.bin/sudo/goodpath.c, Revision 1.1.1.1.6.1

1.1       millert     1: /*
1.1.1.1.6.1! millert     2:  * Copyright (c) 1996, 1998, 1999, 2001
        !             3:  *     Todd C. Miller <Todd.Miller@courtesan.com>.  All rights reserved.
1.1       millert     4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  *
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  *
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  *
                     16:  * 3. The name of the author may not be used to endorse or promote products
                     17:  *    derived from this software without specific prior written permission.
                     18:  *
                     19:  * 4. Products derived from this software may not be called "Sudo" nor
                     20:  *    may "Sudo" appear in their names without specific prior written
                     21:  *    permission from the author.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                     24:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                     25:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
                     26:  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
                     27:  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
                     28:  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
                     29:  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
                     30:  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
                     31:  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
                     32:  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     33:  */
                     34:
                     35: #include "config.h"
                     36:
1.1.1.1.6.1! millert    37: #include <sys/types.h>
        !            38: #include <sys/stat.h>
        !            39: #include <sys/param.h>
1.1       millert    40: #include <stdio.h>
                     41: #ifdef HAVE_STRING_H
1.1.1.1.6.1! millert    42: # include <string.h>
        !            43: #else
        !            44: # ifdef HAVE_STRINGS_H
        !            45: #  include <strings.h>
        !            46: # endif
1.1       millert    47: #endif /* HAVE_STRING_H */
1.1.1.1.6.1! millert    48: #ifdef HAVE_UNISTD_H
        !            49: # include <unistd.h>
        !            50: #endif /* HAVE_UNISTD_H */
1.1       millert    51: #include <errno.h>
                     52:
                     53: #include "sudo.h"
                     54:
                     55: #ifndef lint
1.1.1.1.6.1! millert    56: static const char rcsid[] = "$Sudo: goodpath.c,v 1.38 2001/12/14 19:52:47 millert Exp $";
1.1       millert    57: #endif /* lint */
                     58:
                     59: /*
                     60:  * Verify that path is a normal file and executable by root.
                     61:  */
                     62: char *
                     63: sudo_goodpath(path)
                     64:     const char *path;
                     65: {
                     66:     struct stat sb;
                     67:
                     68:     /* Check for brain damage */
                     69:     if (path == NULL || path[0] == '\0')
                     70:        return(NULL);
                     71:
                     72:     if (stat(path, &sb))
                     73:        return(NULL);
                     74:
                     75:     /* Make sure path describes an executable regular file. */
                     76:     if (!S_ISREG(sb.st_mode) || !(sb.st_mode & 0000111)) {
                     77:        errno = EACCES;
                     78:        return(NULL);
                     79:     }
                     80:
                     81:     return((char *)path);
                     82: }