Ignore:
Timestamp:
Apr 9, 2010, 3:51:41 PM (15 years ago)
Author:
Silvan Scherrer
Message:

Samba 3.5.x: trunk update to 3.5.2

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/client/mount.cifs.c

    r414 r429  
    4444
    4545#define MOUNT_CIFS_VERSION_MAJOR "1"
    46 #define MOUNT_CIFS_VERSION_MINOR "13"
     46#define MOUNT_CIFS_VERSION_MINOR "14"
    4747
    4848#ifndef MOUNT_CIFS_VENDOR_SUFFIX
     
    8888/* currently maximum length of IPv6 address string */
    8989#define MAX_ADDRESS_LEN INET6_ADDRSTRLEN
     90
     91/*
     92 * mount.cifs has been the subject of many "security" bugs that have arisen
     93 * because of users and distributions installing it as a setuid root program.
     94 * mount.cifs has not been audited for security. Thus, we strongly recommend
     95 * that it not be installed setuid root. To make that abundantly clear,
     96 * mount.cifs now check whether it's running setuid root and exit with an
     97 * error if it is. If you wish to disable this check, then set the following
     98 * #define to 1, but please realize that you do so at your own peril.
     99 */
     100#define CIFS_DISABLE_SETUID_CHECK 0
    90101
    91102/*
     
    180191
    181192        /* does mountpoint exist and is it a directory? */
    182         err = stat(mountpoint, &statbuf);
     193        err = stat(".", &statbuf);
    183194        if (err) {
    184195                fprintf(stderr, "%s: failed to stat %s: %s\n", progname,
     
    213224        return 0;
    214225}
     226
     227#if CIFS_DISABLE_SETUID_CHECK
     228static int
     229check_setuid(void)
     230{
     231        return 0;
     232}
     233#else /* CIFS_DISABLE_SETUID_CHECK */
     234static int
     235check_setuid(void)
     236{
     237        if (getuid() && !geteuid()) {
     238                printf("This mount.cifs program has been built with the "
     239                        "ability to run as a setuid root program disabled.\n"
     240                        "mount.cifs has not been well audited for security "
     241                        "holes. Therefore the Samba team does not recommend "
     242                        "installing it as a setuid root program.\n");
     243                return 1;
     244        }
     245
     246        return 0;
     247}
     248#endif /* CIFS_DISABLE_SETUID_CHECK */
    215249
    216250#if CIFS_LEGACY_SETUID_CHECK
     
    11661200}
    11671201
     1202/*
     1203 * This function borrowed from fuse-utils...
     1204 *
     1205 * glibc's addmntent (at least as of 2.10 or so) doesn't properly encode
     1206 * newlines embedded within the text fields. To make sure no one corrupts
     1207 * the mtab, fail the mount if there are embedded newlines.
     1208 */
     1209static int check_newline(const char *progname, const char *name)
     1210{
     1211    char *s;
     1212    for (s = "\n"; *s; s++) {
     1213        if (strchr(name, *s)) {
     1214            fprintf(stderr, "%s: illegal character 0x%02x in mount entry\n",
     1215                    progname, *s);
     1216            return EX_USAGE;
     1217        }
     1218    }
     1219    return 0;
     1220}
     1221
     1222static int check_mtab(const char *progname, const char *devname,
     1223                        const char *dir)
     1224{
     1225        if (check_newline(progname, devname) == -1 ||
     1226            check_newline(progname, dir) == -1)
     1227                return EX_USAGE;
     1228        return 0;
     1229}
     1230
     1231
    11681232int main(int argc, char ** argv)
    11691233{
     
    11981262        FILE * pmntfile;
    11991263
     1264        if (check_setuid())
     1265                return EX_USAGE;
     1266
    12001267        /* setlocale(LC_ALL, "");
    12011268        bindtextdomain(PACKAGE, LOCALEDIR);
     
    13791446
    13801447        /* make sure mountpoint is legit */
     1448        rc = chdir(mountpoint);
     1449        if (rc) {
     1450                fprintf(stderr, "Couldn't chdir to %s: %s\n", mountpoint,
     1451                                strerror(errno));
     1452                rc = EX_USAGE;
     1453                goto mount_exit;
     1454        }
     1455
    13811456        rc = check_mountpoint(thisprogram, mountpoint);
    13821457        if (rc)
     
    14411516        /* BB save off path and pop after mount returns? */
    14421517        resolved_path = (char *)malloc(PATH_MAX+1);
    1443         if(resolved_path) {
    1444                 /* Note that if we can not canonicalize the name, we get
    1445                 another chance to see if it is valid when we chdir to it */
    1446                 if (realpath(mountpoint, resolved_path)) {
    1447                         mountpoint = resolved_path;
    1448                 }
    1449         }
     1518        if (!resolved_path) {
     1519                fprintf(stderr, "Unable to allocate memory.\n");
     1520                rc = EX_SYSERR;
     1521                goto mount_exit;
     1522        }
     1523
     1524        /* Note that if we can not canonicalize the name, we get
     1525           another chance to see if it is valid when we chdir to it */
     1526        if(!realpath(".", resolved_path)) {
     1527                fprintf(stderr, "Unable to resolve %s to canonical path: %s\n",
     1528                                mountpoint, strerror(errno));
     1529                rc = EX_SYSERR;
     1530                goto mount_exit;
     1531        }
     1532
     1533        mountpoint = resolved_path;
     1534
    14501535        if(got_user == 0) {
    14511536                /* Note that the password will not be retrieved from the
     
    15911676                fprintf(stderr, "\n");
    15921677
    1593         if (!fakemnt && mount(dev_name, mountpoint, "cifs", flags, options)) {
     1678        rc = check_mtab(thisprogram, dev_name, mountpoint);
     1679        if (rc)
     1680                goto mount_exit;
     1681
     1682        if (!fakemnt && mount(dev_name, ".", "cifs", flags, options)) {
    15941683                switch (errno) {
    15951684                case ECONNREFUSED:
Note: See TracChangeset for help on using the changeset viewer.