Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Misc/setuid-prog.c

    r2 r388  
    2222   Assuming the script is a Bourne shell script, the first line of the
    2323   script should be
    24         #!/bin/sh -
     24    #!/bin/sh -
    2525   The - is important, don't omit it.  If you're using esh, the first
    2626   line should be
    27         #!/usr/local/bin/esh -f
     27    #!/usr/local/bin/esh -f
    2828   and for ksh, the first line should be
    29         #!/usr/local/bin/ksh -p
     29    #!/usr/local/bin/ksh -p
    3030   The script should then set the variable IFS to the string
    3131   consisting of <space>, <tab>, and <newline>.  After this (*not*
     
    3434   not trust the old value of PATH.  You should then set the umask of
    3535   the program by calling
    36         umask 077 # or 022 if you want the files to be readable
     36    umask 077 # or 022 if you want the files to be readable
    3737   If you plan to change directories, you should either unset CDPATH
    3838   or set it to a good value.  Setting CDPATH to just ``.'' (dot) is a
    3939   good idea.
    4040   If, for some reason, you want to use csh, the first line should be
    41         #!/bin/csh -fb
     41    #!/bin/csh -fb
    4242   You should then set the path variable to something reasonable,
    4343   without trusting the inherited path.  Here too, you should set the
    4444   umask using the command
    45         umask 077 # or 022 if you want the files to be readable
     45    umask 077 # or 022 if you want the files to be readable
    4646*/
    4747
     
    5555/* CONFIGURATION SECTION */
    5656
    57 #ifndef FULL_PATH       /* so that this can be specified from the Makefile */
     57#ifndef FULL_PATH       /* so that this can be specified from the Makefile */
    5858/* Uncomment the following line:
    59 #define FULL_PATH       "/full/path/of/script"
     59#define FULL_PATH       "/full/path/of/script"
    6060* Then comment out the #error line. */
    6161#error "You must define FULL_PATH somewhere"
    6262#endif
    6363#ifndef UMASK
    64 #define UMASK           077
     64#define UMASK           077
    6565#endif
    6666
     
    102102clean_environ(void)
    103103{
    104         char **p;
    105         extern char **environ;
     104    char **p;
     105    extern char **environ;
    106106
    107         for (p = environ; *p; p++) {
    108                 if (strncmp(*p, "LD_", 3) == 0)
    109                         **p = 'X';
    110                 else if (strncmp(*p, "_RLD", 4) == 0)
    111                         **p = 'X';
    112                 else if (strncmp(*p, "PYTHON", 6) == 0)
    113                         **p = 'X';
    114                 else if (strncmp(*p, "IFS=", 4) == 0)
    115                         *p = def_IFS;
    116                 else if (strncmp(*p, "CDPATH=", 7) == 0)
    117                         *p = def_CDPATH;
    118                 else if (strncmp(*p, "ENV=", 4) == 0)
    119                         *p = def_ENV;
    120         }
    121         putenv(def_PATH);
     107    for (p = environ; *p; p++) {
     108        if (strncmp(*p, "LD_", 3) == 0)
     109            **p = 'X';
     110        else if (strncmp(*p, "_RLD", 4) == 0)
     111            **p = 'X';
     112        else if (strncmp(*p, "PYTHON", 6) == 0)
     113            **p = 'X';
     114        else if (strncmp(*p, "IFS=", 4) == 0)
     115            *p = def_IFS;
     116        else if (strncmp(*p, "CDPATH=", 7) == 0)
     117            *p = def_CDPATH;
     118        else if (strncmp(*p, "ENV=", 4) == 0)
     119            *p = def_ENV;
     120    }
     121    putenv(def_PATH);
    122122}
    123123
     
    125125main(int argc, char **argv)
    126126{
    127         struct stat statb;
    128         gid_t egid = getegid();
    129         uid_t euid = geteuid();
     127    struct stat statb;
     128    gid_t egid = getegid();
     129    uid_t euid = geteuid();
    130130
    131         /*
    132            Sanity check #1.
    133            This check should be made compile-time, but that's not possible.
    134            If you're sure that you specified a full path name for FULL_PATH,
    135            you can omit this check.
    136         */
    137         if (FULL_PATH[0] != '/') {
    138                 fprintf(stderr, "%s: %s is not a full path name\n", argv[0],
    139                         FULL_PATH);
    140                 fprintf(stderr, "You can only use this wrapper if you\n");
    141                 fprintf(stderr, "compile it with an absolute path.\n");
    142                 exit(1);
    143         }
     131    /*
     132       Sanity check #1.
     133       This check should be made compile-time, but that's not possible.
     134       If you're sure that you specified a full path name for FULL_PATH,
     135       you can omit this check.
     136    */
     137    if (FULL_PATH[0] != '/') {
     138        fprintf(stderr, "%s: %s is not a full path name\n", argv[0],
     139            FULL_PATH);
     140        fprintf(stderr, "You can only use this wrapper if you\n");
     141        fprintf(stderr, "compile it with an absolute path.\n");
     142        exit(1);
     143    }
    144144
    145         /*
    146            Sanity check #2.
    147            Check that the owner of the script is equal to either the
    148            effective uid or the super user.
    149         */
    150         if (stat(FULL_PATH, &statb) < 0) {
    151                 perror("stat");
    152                 exit(1);
    153         }
    154         if (statb.st_uid != 0 && statb.st_uid != euid) {
    155                 fprintf(stderr, "%s: %s has the wrong owner\n", argv[0],
    156                         FULL_PATH);
    157                 fprintf(stderr, "The script should be owned by root,\n");
    158                 fprintf(stderr, "and shouldn't be writeable by anyone.\n");
    159                 exit(1);
    160         }
     145    /*
     146       Sanity check #2.
     147       Check that the owner of the script is equal to either the
     148       effective uid or the super user.
     149    */
     150    if (stat(FULL_PATH, &statb) < 0) {
     151        perror("stat");
     152        exit(1);
     153    }
     154    if (statb.st_uid != 0 && statb.st_uid != euid) {
     155        fprintf(stderr, "%s: %s has the wrong owner\n", argv[0],
     156            FULL_PATH);
     157        fprintf(stderr, "The script should be owned by root,\n");
     158        fprintf(stderr, "and shouldn't be writeable by anyone.\n");
     159        exit(1);
     160    }
    161161
    162         if (setregid(egid, egid) < 0)
    163                 perror("setregid");
    164         if (setreuid(euid, euid) < 0)
    165                 perror("setreuid");
     162    if (setregid(egid, egid) < 0)
     163        perror("setregid");
     164    if (setreuid(euid, euid) < 0)
     165        perror("setreuid");
    166166
    167         clean_environ();
     167    clean_environ();
    168168
    169         umask(UMASK);
     169    umask(UMASK);
    170170
    171         while (**argv == '-')   /* don't let argv[0] start with '-' */
    172                 (*argv)++;
    173         execv(FULL_PATH, argv);
    174         fprintf(stderr, "%s: could not execute the script\n", argv[0]);
    175         exit(1);
     171    while (**argv == '-')       /* don't let argv[0] start with '-' */
     172        (*argv)++;
     173    execv(FULL_PATH, argv);
     174    fprintf(stderr, "%s: could not execute the script\n", argv[0]);
     175    exit(1);
    176176}
Note: See TracChangeset for help on using the changeset viewer.