Changeset 312


Ignore:
Timestamp:
Aug 5, 2009, 6:34:45 PM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.0 to final 3.0.36 (source)

Location:
branches/samba-3.0/source
Files:
4 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.0/source/Makefile.in

    r165 r312  
    145145# Note that all executable programs now provide for an optional executable suffix.
    146146
    147 SBIN_PROGS = bin/smbd@EXEEXT@ bin/nmbd@EXEEXT@ bin/swat@EXEEXT@ @EXTRA_SBIN_PROGS@ @CIFSUPCALL_PROGS@
     147SBIN_PROGS = bin/smbd@EXEEXT@ bin/nmbd@EXEEXT@ bin/swat@EXEEXT@ @EXTRA_SBIN_PROGS@
    148148
    149149ROOT_SBIN_PROGS = @CIFSMOUNT_PROGS@
     
    16001600
    16011601installcifsupcall: @CIFSUPCALL_PROGS@
    1602         @$(SHELL) $(srcdir)/script/installdirs.sh $(INSTALLPERMS_BIN) $(DESTDIR) $(SBINDIR)
    1603         @$(SHELL) script/installbin.sh $(INSTALLPERMS_BIN) $(DESTDIR) $(prefix) $(SBINDIR) @CIFSUPCALL_PROGS@
     1602        @$(SHELL) $(srcdir)/script/installdirs.sh $(INSTALLPERMS) $(DESTDIR) $(SBINDIR)
     1603        @$(SHELL) script/installbin.sh $(INSTALLPERMS) $(DESTDIR) $(prefix) $(SBINDIR) @CIFSUPCALL_PROGS@
    16041604
    16051605# Some symlinks are required for the 'probing' of modules.
     
    17351735
    17361736uninstallcifsupcall:
    1737         @$(SHELL) script/uninstallbin.sh $(INSTALLPERMS_BIN) $(DESTDIR) $(prefix) $(ROOTSBINDIR) @CIFSUPCALL_PROGS@
     1737        @$(SHELL) script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR) $(prefix) $(ROOTSBINDIR) @CIFSUPCALL_PROGS@
    17381738
    17391739uninstallmodules:
  • branches/samba-3.0/source/VERSION

    r286 r312  
    2626SAMBA_VERSION_MAJOR=3
    2727SAMBA_VERSION_MINOR=0
    28 SAMBA_VERSION_RELEASE=35
     28SAMBA_VERSION_RELEASE=36
    2929
    3030########################################################
     
    9696#  ->  "CVS 3.0.0rc2-VendorVersion"                    #
    9797########################################################
    98 SAMBA_VERSION_VENDOR_SUFFIX=
     98SAMBA_VERSION_VENDOR_SUFFIX="eCS 1.0.2"
    9999SAMBA_VERSION_VENDOR_PATCH=
  • branches/samba-3.0/source/client/mount.cifs.c

    r165 r312  
    22   Mount helper utility for Linux CIFS VFS (virtual filesystem) client
    33   Copyright (C) 2003,2008 Steve French  (sfrench@us.ibm.com)
     4   Copyright (C) 2008 Jeremy Allison (jra@samba.org)
    45
    56   This program is free software; you can redistribute it and/or modify
    67   it under the terms of the GNU General Public License as published by
    7    the Free Software Foundation; either version 2 of the License, or
     8   the Free Software Foundation; either version 3 of the License, or
    89   (at your option) any later version.
    910   
     
    1415   
    1516   You should have received a copy of the GNU General Public License
    16    along with this program; if not, write to the Free Software
    17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
     17   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1818
    1919#ifndef _GNU_SOURCE
     
    5858#endif /* MOUNT_CIFS_VENDOR_SUFFIX */
    5959
     60#ifdef _SAMBA_BUILD_
     61#include "include/config.h"
     62#endif
     63
    6064#ifndef MS_MOVE
    6165#define MS_MOVE 8192
     
    7074#define CONST_DISCARD(type, ptr)      ((type) ((void *) (ptr)))
    7175
     76#ifndef SAFE_FREE
     77#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
     78#endif
     79
     80#define MOUNT_PASSWD_SIZE 64
     81#define DOMAIN_SIZE 64
     82
     83/* currently maximum length of IPv6 address string */
     84#define MAX_ADDRESS_LEN INET6_ADDRSTRLEN
     85
    7286const char *thisprogram;
    7387int verboseflag = 0;
     88int fakemnt = 0;
    7489static int got_password = 0;
    7590static int got_user = 0;
     
    89104/* like strncpy but does not 0 fill the buffer and always null
    90105 *    terminates. bufsize is the size of the destination buffer */
     106
     107#ifndef HAVE_STRLCPY
    91108static size_t strlcpy(char *d, const char *s, size_t bufsize)
    92109{
     
    99116        return ret;
    100117}
     118#endif
    101119
    102120/* like strncat but does not 0 fill the buffer and always null
    103121 *    terminates. bufsize is the length of the buffer, which should
    104122 *       be one more than the maximum resulting string length */
     123
     124#ifndef HAVE_STRLCAT
    105125static size_t strlcat(char *d, const char *s, size_t bufsize)
    106126{
     
    121141        return ret;
    122142}
     143#endif
    123144
    124145/* BB finish BB
     
    143164        printf("\n\tcredentials=<filename>,guest,perm,noperm,setuids,nosetuids,rw,ro,");
    144165        printf("\n\tsep=<char>,iocharset=<codepage>,suid,nosuid,exec,noexec,serverino,");
    145         printf("\n\tdirectio,mapchars,nomapchars,nolock,servernetbiosname=<SRV_RFC1001NAME>");
     166        printf("\n\tmapchars,nomapchars,nolock,servernetbiosname=<SRV_RFC1001NAME>");
     167        printf("\n\tdirectio,nounix,cifsacl,sec=<authentication mechanism>,sign");
    146168        printf("\n\nOptions not needed for servers supporting CIFS Unix extensions");
    147169        printf("\n\t(e.g. unneeded for mounts to most Samba versions):");
     
    150172        printf("\n\tport=<tcpport>,rsize=<size>,wsize=<size>,unc=<unc_name>,ip=<ip_address>,");
    151173        printf("\n\tdev,nodev,nouser_xattr,netbiosname=<OUR_RFC1001NAME>,hard,soft,intr,");
    152         printf("\n\tnointr,ignorecase,noposixpaths,noacl");
     174        printf("\n\tnointr,ignorecase,noposixpaths,noacl,prefixpath=<path>,nobrl");
     175        printf("\n\tin6_addr");
    153176        printf("\n\nOptions are described in more detail in the manual page");
    154177        printf("\n\tman 8 mount.cifs\n");
     
    156179        printf("\n\t%s -V\n",thisprogram);
    157180
    158         if(mountpassword) {
    159                 memset(mountpassword,0,64);
    160                 free(mountpassword);
    161                 mountpassword = NULL;
    162         }
     181        SAFE_FREE(mountpassword);
    163182        exit(EX_USAGE);
    164183}
     
    173192        }
    174193        return username;
    175 }
    176 
    177 static char * parse_cifs_url(char * unc_name)
    178 {
    179         printf("\nMounting cifs URL not implemented yet. Attempt to mount %s\n",unc_name);
    180         return NULL;
    181194}
    182195
     
    193206        if(line_buf == NULL) {
    194207                fclose(fs);
    195                 return -ENOMEM;
     208                return ENOMEM;
    196209        }
    197210
     
    213226                                        if ((temp_val[length] == '\n')
    214227                                            || (temp_val[length] == '\0')) {
     228                                                temp_val[length] = '\0';
    215229                                                break;
    216230                                        }
     
    219233                                        printf("mount.cifs failed due to malformed username in credentials file");
    220234                                        memset(line_buf,0,4096);
    221                                         if(mountpassword) {
    222                                                 memset(mountpassword,0,64);
    223                                         }
    224235                                        exit(EX_USAGE);
    225236                                } else {
     
    228239                                        /* BB adding free of user_name string before exit,
    229240                                                not really necessary but would be cleaner */
    230                                         strncpy(user_name,temp_val, length);
     241                                        strlcpy(user_name,temp_val, length+1);
    231242                                }
    232243                        }
     
    236247                                /* go past equals sign */
    237248                                temp_val++;
    238                                 for(length = 0;length<65;length++) {
     249                                for(length = 0;length<MOUNT_PASSWD_SIZE+1;length++) {
    239250                                        if ((temp_val[length] == '\n')
    240251                                            || (temp_val[length] == '\0')) {
     252                                                temp_val[length] = '\0';
    241253                                                break;
    242254                                        }
    243255                                }
    244                                 if(length > 64) {
     256                                if(length > MOUNT_PASSWD_SIZE) {
    245257                                        printf("mount.cifs failed: password in credentials file too long\n");
    246258                                        memset(line_buf,0, 4096);
    247                                         if(mountpassword) {
    248                                                 memset(mountpassword,0,64);
    249                                         }
    250259                                        exit(EX_USAGE);
    251260                                } else {
    252261                                        if(mountpassword == NULL) {
    253                                                 mountpassword = (char *)calloc(65,1);
     262                                                mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
    254263                                        } else
    255                                                 memset(mountpassword,0,64);
     264                                                memset(mountpassword,0,MOUNT_PASSWD_SIZE);
    256265                                        if(mountpassword) {
    257                                                 strncpy(mountpassword,temp_val,length);
     266                                                strlcpy(mountpassword,temp_val,MOUNT_PASSWD_SIZE+1);
    258267                                                got_password = 1;
    259268                                        }
     
    267276                                if(verboseflag)
    268277                                        printf("\nDomain %s\n",temp_val);
    269                                 for(length = 0;length<65;length++) {
     278                                for(length = 0;length<DOMAIN_SIZE+1;length++) {
    270279                                        if ((temp_val[length] == '\n')
    271280                                            || (temp_val[length] == '\0')) {
     281                                                temp_val[length] = '\0';
    272282                                                break;
    273283                                        }
    274284                                }
    275                                 if(length > 64) {
     285                                if(length > DOMAIN_SIZE) {
    276286                                        printf("mount.cifs failed: domain in credentials file too long\n");
    277                                         if(mountpassword) {
    278                                                 memset(mountpassword,0,64);
    279                                         }
    280287                                        exit(EX_USAGE);
    281288                                } else {
    282289                                        if(domain_name == NULL) {
    283                                                 domain_name = (char *)calloc(65,1);
     290                                                domain_name = (char *)calloc(DOMAIN_SIZE+1,1);
    284291                                        } else
    285                                                 memset(domain_name,0,64);
     292                                                memset(domain_name,0,DOMAIN_SIZE);
    286293                                        if(domain_name) {
    287                                                 strncpy(domain_name,temp_val,length);
     294                                                strlcpy(domain_name,temp_val,DOMAIN_SIZE+1);
    288295                                                got_domain = 1;
    289296                                        }
     
    294301        }
    295302        fclose(fs);
    296         if(line_buf) {
    297                 memset(line_buf,0,4096);
    298                 free(line_buf);
    299                 line_buf = NULL;
    300         }
     303        SAFE_FREE(line_buf);
    301304        return 0;
    302305}
     
    309312
    310313        if(mountpassword == NULL)
    311                 mountpassword = (char *)calloc(65,1);
     314                mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
    312315        else
    313                 memset(mountpassword, 0, 64);
     316                memset(mountpassword, 0, MOUNT_PASSWD_SIZE);
    314317
    315318        if (mountpassword == NULL) {
     
    328331        /* else file already open and fd provided */
    329332
    330         for(i=0;i<64;i++) {
     333        for(i=0;i<MOUNT_PASSWD_SIZE;i++) {
    331334                rc = read(file_descript,&c,1);
    332335                if(rc < 0) {
    333336                        printf("mount.cifs failed. Error %s reading password file\n",strerror(errno));
    334                         memset(mountpassword,0,64);
    335337                        if(filename != NULL)
    336338                                close(file_descript);
     
    344346                } else /* read valid character */ {
    345347                        if((c == 0) || (c == '\n')) {
     348                                mountpassword[i] = '\0';
    346349                                break;
    347350                        } else
     
    349352                }
    350353        }
    351         if((i == 64) && (verboseflag)) {
    352                 printf("\nWarning: password longer than 64 characters specified in cifs password file");
     354        if((i == MOUNT_PASSWD_SIZE) && (verboseflag)) {
     355                printf("\nWarning: password longer than %d characters specified in cifs password file",
     356                        MOUNT_PASSWD_SIZE);
    353357        }
    354358        got_password = 1;
     
    428432                                } else {
    429433                                        printf("username specified with no parameter\n");
     434                                        SAFE_FREE(out);
    430435                                        return 1;       /* needs_arg; */
    431436                                }
     
    437442                                                *percent_char = ',';
    438443                                                if(mountpassword == NULL)
    439                                                         mountpassword = (char *)calloc(65,1);
     444                                                        mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
    440445                                                if(mountpassword) {
    441446                                                        if(got_password)
     
    443448                                                        got_password = 1;
    444449                                                        percent_char++;
    445                                                         strncpy(mountpassword, percent_char,64);
     450                                                        strlcpy(mountpassword, percent_char,MOUNT_PASSWD_SIZE+1);
    446451                                                /*  remove password from username */
    447452                                                        while(*percent_char != 0) {
     
    460465                                } else {
    461466                                        printf("username too long\n");
     467                                        SAFE_FREE(out);
    462468                                        return 1;
    463469                                }
     
    475481                        } else {
    476482                                printf("password too long\n");
     483                                SAFE_FREE(out);
    477484                                return 1;
    478485                        }
     
    486493                        if (!value || !*value) {
    487494                                printf("target ip address argument missing");
    488                         } else if (strnlen(value, 35) < 35) {
     495                        } else if (strnlen(value, MAX_ADDRESS_LEN) <= MAX_ADDRESS_LEN) {
    489496                                if(verboseflag)
    490497                                        printf("ip address %s override specified\n",value);
     
    492499                        } else {
    493500                                printf("ip address too long\n");
     501                                SAFE_FREE(out);
    494502                                return 1;
    495503                        }
     
    499507                        if (!value || !*value) {
    500508                                printf("invalid path to network resource\n");
     509                                SAFE_FREE(out);
    501510                                return 1;  /* needs_arg; */
    502511                        } else if(strnlen(value,5) < 5) {
     
    513522                                } else if (strncmp(value, "\\\\", 2) != 0) {                       
    514523                                        printf("UNC Path does not begin with // or \\\\ \n");
     524                                        SAFE_FREE(out);
    515525                                        return 1;
    516526                                } else {
     
    522532                        } else {
    523533                                printf("CIFS: UNC name too long\n");
     534                                SAFE_FREE(out);
    524535                                return 1;
    525536                        }
    526                 } else if ((strncmp(data, "domain", 3) == 0)
    527                            || (strncmp(data, "workgroup", 5) == 0)) {
     537                } else if ((strncmp(data, "dom" /* domain */, 3) == 0)
     538                           || (strncmp(data, "workg", 5) == 0)) {
     539                        /* note this allows for synonyms of "domain"
     540                           such as "DOM" and "dom" and "workgroup"
     541                           and "WORKGRP" etc. */
    528542                        if (!value || !*value) {
    529543                                printf("CIFS: invalid domain name\n");
     544                                SAFE_FREE(out);
    530545                                return 1;       /* needs_arg; */
    531546                        }
    532                         if (strnlen(value, 65) < 65) {
     547                        if (strnlen(value, DOMAIN_SIZE+1) < DOMAIN_SIZE+1) {
    533548                                got_domain = 1;
    534549                        } else {
    535550                                printf("domain name too long\n");
     551                                SAFE_FREE(out);
    536552                                return 1;
    537553                        }
     
    540556                                rc = open_cred_file(value);
    541557                                if(rc) {
    542                                         printf("error %d opening credential file %s\n",rc, value);
     558                                        printf("error %d (%s) opening credential file %s\n",
     559                                                rc, strerror(rc), value);
     560                                        SAFE_FREE(out);
    543561                                        return 1;
    544562                                }
    545563                        } else {
    546564                                printf("invalid credential file name specified\n");
     565                                SAFE_FREE(out);
    547566                                return 1;
    548567                        }
     
    583602                        if (!value || !*value) {
    584603                                printf ("Option '%s' requires a numerical argument\n", data);
     604                                SAFE_FREE(out);
    585605                                return 1;
    586606                        }
     
    597617                        if (!value || !*value) {
    598618                                printf ("Option '%s' requires a numerical argument\n", data);
     619                                SAFE_FREE(out);
    599620                                return 1;
    600621                        }
     
    630651                        *filesys_flags &= ~MS_NOEXEC;
    631652                } else if (strncmp(data, "guest", 5) == 0) {
    632                         got_password=1;
     653                        user_name = (char *)calloc(1, 1);
     654                        got_user = 1;
     655                        got_password = 1;
    633656                } else if (strncmp(data, "ro", 2) == 0) {
    634657                        *filesys_flags |= MS_RDONLY;
     
    718741        }
    719742
    720         free(*optionsp);
     743        SAFE_FREE(*optionsp);
    721744        *optionsp = out;
    722745        return 0;
     
    746769        if(number_of_commas == 0)
    747770                return;
    748         if(number_of_commas > 64) {
     771        if(number_of_commas > MOUNT_PASSWD_SIZE) {
    749772                /* would otherwise overflow the mount options buffer */
    750773                printf("\nInvalid password. Password contains too many commas.\n");
     
    765788        new_pass_buf[len+number_of_commas] = 0;
    766789
    767         free(*ppasswrd);
     790        SAFE_FREE(*ppasswrd);
    768791        *ppasswrd = new_pass_buf;
    769792       
     
    860883
    861884/* Note that caller frees the returned buffer if necessary */
    862 static char * parse_server(char ** punc_name)
     885static struct addrinfo *
     886parse_server(char ** punc_name)
    863887{
    864888        char * unc_name = *punc_name;
    865889        int length = strnlen(unc_name, MAX_UNC_LEN);
    866890        char * share;
    867         char * ipaddress_string = NULL;
    868         struct hostent * host_entry = NULL;
    869         struct in_addr server_ipaddr;
     891        struct addrinfo *addrlist;
     892        int rc;
    870893
    871894        if(length > (MAX_UNC_LEN - 1)) {
     
    873896                return NULL;
    874897        }
    875         if (strncasecmp("cifs://",unc_name,7) == 0)
    876                 return parse_cifs_url(unc_name+7);
    877         if (strncasecmp("smb://",unc_name,6) == 0) {
    878                 return parse_cifs_url(unc_name+6);
     898        if ((strncasecmp("cifs://", unc_name, 7) == 0) ||
     899            (strncasecmp("smb://", unc_name, 6) == 0)) {
     900                printf("\nMounting cifs URL not implemented yet. Attempt to mount %s\n", unc_name);
     901                return NULL;
    879902        }
    880903
     
    896919                                }
    897920                                *share = '/';
    898                                 strncpy((*punc_name)+2,unc_name,length);
    899                                 free(unc_name);
     921                                strlcpy((*punc_name)+2,unc_name,length+1);
     922                                SAFE_FREE(unc_name);
    900923                                unc_name = *punc_name;
    901924                                unc_name[length+2] = 0;
     
    917940                                share += 1;
    918941                                if(got_ip == 0) {
    919                                         host_entry = gethostbyname(unc_name);
     942                                        rc = getaddrinfo(unc_name, NULL, NULL, &addrlist);
     943                                        if (rc != 0) {
     944                                                printf("mount error: could not resolve address for %s: %s\n",
     945                                                        unc_name, gai_strerror(rc));
     946                                                addrlist = NULL;
     947                                        }
    920948                                }
    921949                                *(share - 1) = '/'; /* put delimiter back */
     
    932960                                        return NULL;
    933961                                }
    934                                 if(host_entry == NULL) {
    935                                         printf("mount error: could not find target server. TCP name %s not found\n", unc_name);
    936                                         return NULL;
    937                                 } else {
    938                                         /* BB should we pass an alternate version of the share name as Unicode */
    939                                         /* BB what about ipv6? BB */
    940                                         /* BB add retries with alternate servers in list */
    941 
    942                                         memcpy(&server_ipaddr.s_addr, host_entry->h_addr, 4);
    943 
    944                                         ipaddress_string = inet_ntoa(server_ipaddr);                                                                                     
    945                                         if(ipaddress_string == NULL) {
    946                                                 printf("mount error: could not get valid ip address for target server\n");
    947                                                 return NULL;
    948                                         }
    949                                         return ipaddress_string;
    950                                 }
     962                                /* BB should we pass an alternate version of the share name as Unicode */
     963
     964                                return addrlist;
    951965                        } else {
    952966                                /* BB add code to find DFS root (send null path on get DFS Referral to specified server here */
     
    10121026        char * orgoptions = NULL;
    10131027        char * share_name = NULL;
    1014         char * ipaddr = NULL;
     1028        const char * ipaddr = NULL;
    10151029        char * uuid = NULL;
    10161030        char * mountpoint = NULL;
    10171031        char * options = NULL;
     1032        char * optionstail;
    10181033        char * resolved_path = NULL;
    10191034        char * temp;
    10201035        char * dev_name;
    1021         int rc;
     1036        int rc = 0;
    10221037        int rsize = 0;
    10231038        int wsize = 0;
     
    10281043        int orgoptlen = 0;
    10291044        size_t options_size = 0;
     1045        size_t current_len;
    10301046        int retry = 0; /* set when we have to retry mount with uppercase */
     1047        struct addrinfo *addrhead = NULL, *addr;
    10311048        struct stat statbuf;
    10321049        struct utsname sysinfo;
    10331050        struct mntent mountent;
     1051        struct sockaddr_in *addr4;
     1052        struct sockaddr_in6 *addr6;
    10341053        FILE * pmntfile;
    10351054
     
    10631082                mountpoint = argv[2];
    10641083        } else {
     1084                if ((strcmp (argv[1], "--version") == 0) ||
     1085                    ((strcmp (argv[1], "-V") == 0))) {
     1086                        printf ("mount.cifs version: %s.%s%s\n",
     1087                        MOUNT_CIFS_VERSION_MAJOR,
     1088                        MOUNT_CIFS_VERSION_MINOR,
     1089                        MOUNT_CIFS_VENDOR_SUFFIX);
     1090                        exit (0);
     1091                }
    10651092                mount_cifs_usage();
    10661093                exit(EX_USAGE);
     
    10881115                        exit(EX_USAGE);
    10891116                case 'n':
    1090                     ++nomtab;
    1091                     break;
     1117                        ++nomtab;
     1118                        break;
    10921119                case 'b':
    10931120#ifdef MS_BIND
     
    11231150                        MOUNT_CIFS_VERSION_MINOR,
    11241151                        MOUNT_CIFS_VENDOR_SUFFIX);
    1125                         if(mountpassword) {
    1126                                 memset(mountpassword,0,64);
    1127                         }
    11281152                        exit (0);
    11291153                case 'w':
     
    11861210                case 'p':
    11871211                        if(mountpassword == NULL)
    1188                                 mountpassword = (char *)calloc(65,1);
     1212                                mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
    11891213                        if(mountpassword) {
    11901214                                got_password = 1;
    1191                                 strncpy(mountpassword,optarg,64);
     1215                                strlcpy(mountpassword,optarg,MOUNT_PASSWD_SIZE+1);
    11921216                        }
    11931217                        break;
     
    11961220                        break;
    11971221                case 't':
     1222                        break;
     1223                case 'f':
     1224                        ++fakemnt;
    11981225                        break;
    11991226                default:
     
    12111238        if (getenv("PASSWD")) {
    12121239                if(mountpassword == NULL)
    1213                         mountpassword = (char *)calloc(65,1);
     1240                        mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
    12141241                if(mountpassword) {
    1215                         strncpy(mountpassword,getenv("PASSWD"),64);
     1242                        strlcpy(mountpassword,getenv("PASSWD"),MOUNT_PASSWD_SIZE+1);
    12161243                        got_password = 1;
    12171244                }
     
    12261253                goto mount_exit;
    12271254        }
    1228         ipaddr = parse_server(&share_name);
    1229         if((ipaddr == NULL) && (got_ip == 0)) {
     1255        addrhead = addr = parse_server(&share_name);
     1256        if((addrhead == NULL) && (got_ip == 0)) {
    12301257                printf("No ip address specified and hostname not found\n");
    12311258                rc = EX_USAGE;
     
    12741301
    12751302        if(got_user == 0) {
    1276                 user_name = getusername();
     1303                /* Note that the password will not be retrieved from the
     1304                   USER env variable (ie user%password form) as there is
     1305                   already a PASSWD environment varaible */
     1306                if (getenv("USER"))
     1307                        user_name = strdup(getenv("USER"));
     1308                if (user_name == NULL)
     1309                        user_name = getusername();
    12771310                got_user = 1;
    12781311        }
    12791312       
    12801313        if(got_password == 0) {
    1281                 char *tmp_pass;
    1282                 tmp_pass = getpass("Password: "); /* BB obsolete sys call but
    1283                                                      no good replacement yet */
    1284                 mountpassword = (char *)calloc(65,1);
     1314                char *tmp_pass = getpass("Password: "); /* BB obsolete sys call but
     1315                                                           no good replacement yet. */
     1316                mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1);
    12851317                if (!tmp_pass || !mountpassword) {
    12861318                        printf("Password not entered, exiting\n");
    12871319                        exit(EX_USAGE);
    12881320                }
    1289                 strncpy(mountpassword, tmp_pass, 64);
    1290                                                  
     1321                strlcpy(mountpassword, tmp_pass, MOUNT_PASSWD_SIZE+1);
    12911322                got_password = 1;
    12921323        }
    12931324        /* FIXME launch daemon (handles dfs name resolution and credential change)
    12941325           remember to clear parms and overwrite password field before launching */
    1295 mount_retry:
    12961326        if(orgoptions) {
    12971327                optlen = strlen(orgoptions);
     
    13081338        if(user_name)
    13091339                optlen += strlen(user_name) + 6;
    1310         if(ipaddr)
    1311                 optlen += strlen(ipaddr) + 4;
     1340        optlen += MAX_ADDRESS_LEN + 4;
    13121341        if(mountpassword)
    13131342                optlen += strlen(mountpassword) + 6;
    1314         if(options) {
    1315                 free(options);
    1316                 options = NULL;
    1317         }
    1318         options_size = optlen + 10 + 64;
     1343mount_retry:
     1344        SAFE_FREE(options);
     1345        options_size = optlen + 10 + DOMAIN_SIZE;
    13191346        options = (char *)malloc(options_size /* space for commas in password */ + 8 /* space for domain=  , domain name itself was counted as part of the length username string above */);
    13201347
     
    13241351        }
    13251352
    1326         options[0] = 0;
    1327         strlcpy(options,"unc=",options_size);
     1353        strlcpy(options, "unc=", options_size);
    13281354        strlcat(options,share_name,options_size);
    13291355        /* scan backwards and reverse direction of slash */
     
    13311357        if(temp > options + 6)
    13321358                *temp = '\\';
    1333         if(ipaddr) {
    1334                 strlcat(options,",ip=",options_size);
    1335                 strlcat(options,ipaddr,options_size);
    1336         }
    1337 
    13381359        if(user_name) {
    13391360                /* check for syntax like user=domain\user */
     
    13771398        replace_char(dev_name, '\\', '/', strlen(share_name));
    13781399
    1379         if(mount(dev_name, mountpoint, "cifs", flags, options)) {
    1380         /* remember to kill daemon on error */
     1400        if (!got_ip && addr) {
     1401                strlcat(options, ",ip=", options_size);
     1402                current_len = strnlen(options, options_size);
     1403                optionstail = options + current_len;
     1404                switch (addr->ai_addr->sa_family) {
     1405                case AF_INET6:
     1406                        addr6 = (struct sockaddr_in6 *) addr->ai_addr;
     1407                        ipaddr = inet_ntop(AF_INET6, &addr6->sin6_addr, optionstail,
     1408                                           options_size - current_len);
     1409                        break;
     1410                case AF_INET:
     1411                        addr4 = (struct sockaddr_in *) addr->ai_addr;
     1412                        ipaddr = inet_ntop(AF_INET, &addr4->sin_addr, optionstail,
     1413                                           options_size - current_len);
     1414                        break;
     1415                }
     1416
     1417                /* if the address looks bogus, try the next one */
     1418                if (!ipaddr) {
     1419                        addr = addr->ai_next;
     1420                        if (addr)
     1421                                goto mount_retry;
     1422                        rc = EX_SYSERR;
     1423                        goto mount_exit;
     1424                }
     1425        }
     1426
     1427        if (!fakemnt && mount(dev_name, mountpoint, "cifs", flags, options)) {
    13811428                switch (errno) {
    1382                 case 0:
    1383                         printf("mount failed but no error number set\n");
     1429                case ECONNREFUSED:
     1430                case EHOSTUNREACH:
     1431                        if (addr) {
     1432                                addr = addr->ai_next;
     1433                                if (addr)
     1434                                        goto mount_retry;
     1435                        }
    13841436                        break;
    13851437                case ENODEV:
     
    13961448                                }
    13971449                        }
    1398                 default:
    1399                         printf("mount error %d = %s\n",errno,strerror(errno));
    1400                 }
     1450                }
     1451                printf("mount error(%d): %s\n", errno, strerror(errno));
    14011452                printf("Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n");
    14021453                rc = EX_FAIL;
    1403         } else {
    1404                 atexit(unlock_mtab);
    1405                 rc = lock_mtab();
    1406                 if (rc) {
    1407                         printf("cannot lock mtab");
    1408                         goto mount_exit;
    1409                 }
    1410                 pmntfile = setmntent(MOUNTED, "a+");
    1411                 if (!pmntfile) {
    1412                         printf("could not update mount table\n");
    1413                         unlock_mtab();
    1414                         rc = EX_FILEIO;
    1415                         goto mount_exit;
    1416                 }
    1417                 mountent.mnt_fsname = dev_name;
    1418                 mountent.mnt_dir = mountpoint;
    1419                 mountent.mnt_type = CONST_DISCARD(char *,"cifs");
    1420                 mountent.mnt_opts = (char *)malloc(220);
    1421                 if(mountent.mnt_opts) {
    1422                         char * mount_user = getusername();
    1423                         memset(mountent.mnt_opts,0,200);
    1424                         if(flags & MS_RDONLY)
    1425                                 strlcat(mountent.mnt_opts,"ro",220);
    1426                         else
    1427                                 strlcat(mountent.mnt_opts,"rw",220);
    1428                         if(flags & MS_MANDLOCK)
    1429                                 strlcat(mountent.mnt_opts,",mand",220);
    1430                         if(flags & MS_NOEXEC)
    1431                                 strlcat(mountent.mnt_opts,",noexec",220);
    1432                         if(flags & MS_NOSUID)
    1433                                 strlcat(mountent.mnt_opts,",nosuid",220);
    1434                         if(flags & MS_NODEV)
    1435                                 strlcat(mountent.mnt_opts,",nodev",220);
    1436                         if(flags & MS_SYNCHRONOUS)
    1437                                 strlcat(mountent.mnt_opts,",sync",220);
    1438                         if(mount_user) {
    1439                                 if(getuid() != 0) {
    1440                                         strlcat(mountent.mnt_opts,
    1441                                                 ",user=", 220);
    1442                                         strlcat(mountent.mnt_opts,
    1443                                                 mount_user, 220);
    1444                                 }
    1445                         }
    1446                 }
    1447                 mountent.mnt_freq = 0;
    1448                 mountent.mnt_passno = 0;
    1449                 rc = addmntent(pmntfile,&mountent);
    1450                 endmntent(pmntfile);
     1454                goto mount_exit;
     1455        }
     1456
     1457        if (nomtab)
     1458                goto mount_exit;
     1459        atexit(unlock_mtab);
     1460        rc = lock_mtab();
     1461        if (rc) {
     1462                printf("cannot lock mtab");
     1463                goto mount_exit;
     1464        }
     1465        pmntfile = setmntent(MOUNTED, "a+");
     1466        if (!pmntfile) {
     1467                printf("could not update mount table\n");
    14511468                unlock_mtab();
    1452                 if(mountent.mnt_opts) {
    1453                         free(mountent.mnt_opts);
    1454                         mountent.mnt_opts = NULL;
    1455                 }
    1456                 if (rc)
    1457                         rc = EX_FILEIO;
    1458         }
     1469                rc = EX_FILEIO;
     1470                goto mount_exit;
     1471        }
     1472        mountent.mnt_fsname = dev_name;
     1473        mountent.mnt_dir = mountpoint;
     1474        mountent.mnt_type = CONST_DISCARD(char *,"cifs");
     1475        mountent.mnt_opts = (char *)malloc(220);
     1476        if(mountent.mnt_opts) {
     1477                char * mount_user = getusername();
     1478                memset(mountent.mnt_opts,0,200);
     1479                if(flags & MS_RDONLY)
     1480                        strlcat(mountent.mnt_opts,"ro",220);
     1481                else
     1482                        strlcat(mountent.mnt_opts,"rw",220);
     1483                if(flags & MS_MANDLOCK)
     1484                        strlcat(mountent.mnt_opts,",mand",220);
     1485                if(flags & MS_NOEXEC)
     1486                        strlcat(mountent.mnt_opts,",noexec",220);
     1487                if(flags & MS_NOSUID)
     1488                        strlcat(mountent.mnt_opts,",nosuid",220);
     1489                if(flags & MS_NODEV)
     1490                        strlcat(mountent.mnt_opts,",nodev",220);
     1491                if(flags & MS_SYNCHRONOUS)
     1492                        strlcat(mountent.mnt_opts,",sync",220);
     1493                if(mount_user) {
     1494                        if(getuid() != 0) {
     1495                                strlcat(mountent.mnt_opts,
     1496                                        ",user=", 220);
     1497                                strlcat(mountent.mnt_opts,
     1498                                        mount_user, 220);
     1499                        }
     1500                }
     1501        }
     1502        mountent.mnt_freq = 0;
     1503        mountent.mnt_passno = 0;
     1504        rc = addmntent(pmntfile,&mountent);
     1505        endmntent(pmntfile);
     1506        unlock_mtab();
     1507        SAFE_FREE(mountent.mnt_opts);
     1508        if (rc)
     1509                rc = EX_FILEIO;
    14591510mount_exit:
    14601511        if(mountpassword) {
    14611512                int len = strlen(mountpassword);
    14621513                memset(mountpassword,0,len);
    1463                 free(mountpassword);
    1464                 mountpassword = NULL;
    1465         }
    1466 
    1467         if(options) {
    1468                 memset(options,0,optlen);
    1469                 free(options);
    1470                 options = NULL;
    1471         }
    1472 
    1473         if(orgoptions) {
    1474                 memset(orgoptions,0,orgoptlen);
    1475                 free(orgoptions);
    1476                 orgoptions = NULL;
    1477         }
    1478         if(resolved_path) {
    1479                 free(resolved_path);
    1480                 resolved_path = NULL;
    1481         }
    1482 
    1483         free(share_name);
     1514                SAFE_FREE(mountpassword);
     1515        }
     1516
     1517        if (addrhead)
     1518                freeaddrinfo(addrhead);
     1519        SAFE_FREE(options);
     1520        SAFE_FREE(orgoptions);
     1521        SAFE_FREE(resolved_path);
     1522        SAFE_FREE(share_name);
    14841523        exit(rc);
    14851524}
  • branches/samba-3.0/source/client/umount.cifs.c

    r165 r312  
    3535#include <string.h>
    3636#include <mntent.h>
     37#include <limits.h>
    3738#include "mount.h"
    3839
     
    233234}
    234235
     236/* Make a canonical pathname from PATH.  Returns a freshly malloced string.
     237   It is up the *caller* to ensure that the PATH is sensible.  i.e.
     238   canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
     239   is not a legal pathname for ``/dev/fd0''  Anything we cannot parse
     240   we return unmodified.   */
     241static char *
     242canonicalize(char *path)
     243{
     244        char *canonical = malloc (PATH_MAX + 1);
     245
     246        if (!canonical) {
     247                fprintf(stderr, "Error! Not enough memory!\n");
     248                return NULL;
     249        }
     250
     251        if (strlen(path) > PATH_MAX) {
     252                fprintf(stderr, "Mount point string too long\n");
     253                return NULL;
     254        }
     255
     256        if (path == NULL)
     257                return NULL;
     258
     259        if (realpath (path, canonical))
     260                return canonical;
     261
     262        strncpy (canonical, path, PATH_MAX);
     263        canonical[PATH_MAX] = '\0';
     264        return canonical;
     265}
     266
    235267int main(int argc, char ** argv)
    236268{
     
    306338        argc -= optind;
    307339
    308         mountpoint = argv[0];
     340        mountpoint = canonicalize(argv[0]);
    309341
    310342        if((argc < 1) || (argv[0] == NULL)) {
  • branches/samba-3.0/source/configure

    r286 r312  
    1403614036
    1403714037
    14038 
    14039 
    14040 
    14041 for ac_header in netinet/ip.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h
     14038for ac_header in netinet/in_systm.h
     14039do
     14040as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
     14041if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
     14042  { echo "$as_me:$LINENO: checking for $ac_header" >&5
     14043echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
     14044if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
     14045  echo $ECHO_N "(cached) $ECHO_C" >&6
     14046fi
     14047ac_res=`eval echo '${'$as_ac_Header'}'`
     14048               { echo "$as_me:$LINENO: result: $ac_res" >&5
     14049echo "${ECHO_T}$ac_res" >&6; }
     14050else
     14051  # Is the header compilable?
     14052{ echo "$as_me:$LINENO: checking $ac_header usability" >&5
     14053echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; }
     14054cat >conftest.$ac_ext <<_ACEOF
     14055/* confdefs.h.  */
     14056_ACEOF
     14057cat confdefs.h >>conftest.$ac_ext
     14058cat >>conftest.$ac_ext <<_ACEOF
     14059/* end confdefs.h.  */
     14060$ac_includes_default
     14061#include <$ac_header>
     14062_ACEOF
     14063rm -f conftest.$ac_objext
     14064if { (ac_try="$ac_compile"
     14065case "(($ac_try" in
     14066  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
     14067  *) ac_try_echo=$ac_try;;
     14068esac
     14069eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
     14070  (eval "$ac_compile") 2>conftest.er1
     14071  ac_status=$?
     14072  grep -v '^ *+' conftest.er1 >conftest.err
     14073  rm -f conftest.er1
     14074  cat conftest.err >&5
     14075  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     14076  (exit $ac_status); } && {
     14077         test -z "$ac_c_werror_flag" ||
     14078         test ! -s conftest.err
     14079       } && test -s conftest.$ac_objext; then
     14080  ac_header_compiler=yes
     14081else
     14082  echo "$as_me: failed program was:" >&5
     14083sed 's/^/| /' conftest.$ac_ext >&5
     14084
     14085        ac_header_compiler=no
     14086fi
     14087
     14088rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     14089{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
     14090echo "${ECHO_T}$ac_header_compiler" >&6; }
     14091
     14092# Is the header present?
     14093{ echo "$as_me:$LINENO: checking $ac_header presence" >&5
     14094echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; }
     14095cat >conftest.$ac_ext <<_ACEOF
     14096/* confdefs.h.  */
     14097_ACEOF
     14098cat confdefs.h >>conftest.$ac_ext
     14099cat >>conftest.$ac_ext <<_ACEOF
     14100/* end confdefs.h.  */
     14101#include <$ac_header>
     14102_ACEOF
     14103if { (ac_try="$ac_cpp conftest.$ac_ext"
     14104case "(($ac_try" in
     14105  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
     14106  *) ac_try_echo=$ac_try;;
     14107esac
     14108eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
     14109  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
     14110  ac_status=$?
     14111  grep -v '^ *+' conftest.er1 >conftest.err
     14112  rm -f conftest.er1
     14113  cat conftest.err >&5
     14114  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     14115  (exit $ac_status); } >/dev/null && {
     14116         test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
     14117         test ! -s conftest.err
     14118       }; then
     14119  ac_header_preproc=yes
     14120else
     14121  echo "$as_me: failed program was:" >&5
     14122sed 's/^/| /' conftest.$ac_ext >&5
     14123
     14124  ac_header_preproc=no
     14125fi
     14126
     14127rm -f conftest.err conftest.$ac_ext
     14128{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
     14129echo "${ECHO_T}$ac_header_preproc" >&6; }
     14130
     14131# So?  What about this header?
     14132case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
     14133  yes:no: )
     14134    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
     14135echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
     14136    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
     14137echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
     14138    ac_header_preproc=yes
     14139    ;;
     14140  no:yes:* )
     14141    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
     14142echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
     14143    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
     14144echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
     14145    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
     14146echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
     14147    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
     14148echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
     14149    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
     14150echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
     14151    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
     14152echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
     14153
     14154    ;;
     14155esac
     14156{ echo "$as_me:$LINENO: checking for $ac_header" >&5
     14157echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
     14158if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
     14159  echo $ECHO_N "(cached) $ECHO_C" >&6
     14160else
     14161  eval "$as_ac_Header=\$ac_header_preproc"
     14162fi
     14163ac_res=`eval echo '${'$as_ac_Header'}'`
     14164               { echo "$as_me:$LINENO: result: $ac_res" >&5
     14165echo "${ECHO_T}$ac_res" >&6; }
     14166
     14167fi
     14168if test `eval echo '${'$as_ac_Header'}'` = yes; then
     14169  cat >>confdefs.h <<_ACEOF
     14170#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
     14171_ACEOF
     14172
     14173fi
     14174
     14175done
     14176
     14177
     14178for ac_header in netinet/ip.h
     14179do
     14180as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
     14181{ echo "$as_me:$LINENO: checking for $ac_header" >&5
     14182echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
     14183if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
     14184  echo $ECHO_N "(cached) $ECHO_C" >&6
     14185else
     14186  cat >conftest.$ac_ext <<_ACEOF
     14187/* confdefs.h.  */
     14188_ACEOF
     14189cat confdefs.h >>conftest.$ac_ext
     14190cat >>conftest.$ac_ext <<_ACEOF
     14191/* end confdefs.h.  */
     14192#ifdef HAVE_NETINET_IN_H
     14193#include <netinet/in.h>
     14194#endif
     14195#ifdef HAVE_NETINET_IN_SYSTM_H
     14196#include <netinet/in_systm.h>
     14197#endif
     14198
     14199#include <$ac_header>
     14200_ACEOF
     14201rm -f conftest.$ac_objext
     14202if { (ac_try="$ac_compile"
     14203case "(($ac_try" in
     14204  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
     14205  *) ac_try_echo=$ac_try;;
     14206esac
     14207eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
     14208  (eval "$ac_compile") 2>conftest.er1
     14209  ac_status=$?
     14210  grep -v '^ *+' conftest.er1 >conftest.err
     14211  rm -f conftest.er1
     14212  cat conftest.err >&5
     14213  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     14214  (exit $ac_status); } && {
     14215         test -z "$ac_c_werror_flag" ||
     14216         test ! -s conftest.err
     14217       } && test -s conftest.$ac_objext; then
     14218  eval "$as_ac_Header=yes"
     14219else
     14220  echo "$as_me: failed program was:" >&5
     14221sed 's/^/| /' conftest.$ac_ext >&5
     14222
     14223        eval "$as_ac_Header=no"
     14224fi
     14225
     14226rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     14227fi
     14228ac_res=`eval echo '${'$as_ac_Header'}'`
     14229               { echo "$as_me:$LINENO: result: $ac_res" >&5
     14230echo "${ECHO_T}$ac_res" >&6; }
     14231if test `eval echo '${'$as_ac_Header'}'` = yes; then
     14232  cat >>confdefs.h <<_ACEOF
     14233#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
     14234_ACEOF
     14235
     14236fi
     14237
     14238done
     14239
     14240
     14241
     14242for ac_header in netinet/tcp.h netinet/in_ip.h
    1404214243do
    1404314244as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
  • branches/samba-3.0/source/configure.os2

    r23 r312  
    55AR="emxomfar" \
    66LIBS="-lsocket -lsyslog" \
    7 ./configure --prefix=/samba \
     7./configure --prefix=/samba --with-acl-support \
    88         --enable-static --disable-shared \
    99         --disable-ldap --disable-cups  2>&1 | tee configure.log
  • branches/samba-3.0/source/include/includes.h

    r140 r312  
    209209#endif
    210210
    211 #if HAVE_GSSAPI_H
    212 #include <gssapi.h>
    213 #elif HAVE_GSSAPI_GSSAPI_H
     211#if HAVE_GSSAPI_GSSAPI_H
    214212#include <gssapi/gssapi.h>
    215213#elif HAVE_GSSAPI_GSSAPI_GENERIC_H
    216214#include <gssapi/gssapi_generic.h>
     215#elif HAVE_GSSAPI_H
     216#include <gssapi.h>
    217217#endif
    218218
  • branches/samba-3.0/source/include/version.h

    r286 r312  
    22#define SAMBA_VERSION_MAJOR 3
    33#define SAMBA_VERSION_MINOR 0
    4 #define SAMBA_VERSION_RELEASE 35
    5 #define SAMBA_VERSION_OFFICIAL_STRING "3.0.35"
     4#define SAMBA_VERSION_RELEASE 36
     5#define SAMBA_VERSION_OFFICIAL_STRING "3.0.36"
     6#define SAMBA_VERSION_VENDOR_SUFFIX "eCS 1.0.2"
    67#define SAMBA_VERSION_STRING samba_version_string()
  • branches/samba-3.0/source/lib/replace/libreplace.m4

    r124 r312  
    9898AC_CHECK_HEADERS(stdarg.h vararg.h)
    9999AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
    100 AC_CHECK_HEADERS(netinet/ip.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
     100AC_CHECK_HEADERS(netinet/in_systm.h)
     101AC_CHECK_HEADERS([netinet/ip.h], [], [], [#ifdef HAVE_NETINET_IN_H
     102#include <netinet/in.h>
     103#endif
     104#ifdef HAVE_NETINET_IN_SYSTM_H
     105#include <netinet/in_systm.h>
     106#endif])
     107AC_CHECK_HEADERS(netinet/tcp.h netinet/in_ip.h)
    101108AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
    102109AC_CHECK_HEADERS(stropts.h)
  • branches/samba-3.0/source/libaddns/dns.h

    r39 r312  
    7777#endif
    7878
    79 #if HAVE_GSSAPI_H
    80 #include <gssapi.h>
    81 #elif HAVE_GSSAPI_GSSAPI_H
     79#if HAVE_GSSAPI_GSSAPI_H
    8280#include <gssapi/gssapi.h>
    8381#elif HAVE_GSSAPI_GSSAPI_GENERIC_H
    8482#include <gssapi/gssapi_generic.h>
     83#elif HAVE_GSSAPI_H
     84#include <gssapi.h>
    8585#endif
    8686
  • branches/samba-3.0/source/libads/cldap.c

    r22 r312  
    6161                                followed_ptr = 1;
    6262                        }
    63                         len = ((ptr[0] & 0x3f) << 8) | ptr[1];
     63                        len = ((ptr[0] & 0x3f) << 8) | (uint8) ptr[1];
    6464                        ptr = data + len;
    6565                } else if (*ptr) {
  • branches/samba-3.0/source/libads/ldap.c

    r165 r312  
    113113                return LDAP_TIMELIMIT_EXCEEDED;
    114114
     115
     116        /*
     117         * A bug in OpenLDAP means ldap_search_ext_s can return
     118         * LDAP_SUCCESS but with a NULL res pointer. Cope with
     119         * this. See bug #6279 for details. JRA.
     120         */
     121
     122        if (*res == NULL) {
     123                return LDAP_TIMELIMIT_EXCEEDED;
     124        }
     125
    115126        return result;
    116127}
     
    276287                got_realm = True;
    277288                   
     289 again:
     290
    278291        /* we need to try once with the realm name and fallback to the
    279292           netbios domain name if we fail (if netbios has not been disabled */
     
    326339
    327340        sitename = sitename_fetch(realm);
    328 
    329  again:
    330341
    331342        DEBUG(6,("ads_find_dc: (cldap) looking for %s '%s'\n",
  • branches/samba-3.0/source/libsmb/namequery.c

    r165 r312  
    12261226
    12271227        DEBUG(10, ("internal_resolve_name: looking up %s#%x (sitename %s)\n",
    1228                         name, name_type, sitename ? sitename : NULL));
     1228                        name, name_type, sitename ? sitename : "(null)"));
    12291229
    12301230        if (allzeros || allones || is_address) {
  • branches/samba-3.0/source/modules/nfs4_acls.c

    r39 r312  
    588588
    589589        SMB_STRUCT_STAT sbuf;
    590         BOOL need_chown = False;
     590        BOOL set_acl_as_root = False;
    591591        uid_t newUID = (uid_t)-1;
    592592        gid_t newGID = (gid_t)-1;
     593        int saved_errno;
    593594
    594595        DEBUG(10, ("smb_set_nt_acl_nfs4 invoked for %s\n", fsp->fsp_name));
     
    618619                if (((newUID != (uid_t)-1) && (sbuf.st_uid != newUID)) ||
    619620                        ((newGID != (gid_t)-1) && (sbuf.st_gid != newGID))) {
    620                         need_chown = True;
    621                 }
    622                 if (need_chown) {
    623                         if ((newUID == (uid_t)-1 || newUID == current_user.ut.uid)) {
    624                                 if(try_chown(fsp->conn, fsp->fsp_name, newUID, newGID)) {
    625                                         DEBUG(3,("chown %s, %u, %u failed. Error = %s.\n",
    626                                                 fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID, strerror(errno) ));
    627                                         return False;
    628                                 }
    629                                 DEBUG(10,("chown %s, %u, %u succeeded.\n",
    630                                         fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID));
    631                                 if (smbacl4_GetFileOwner(fsp, &sbuf))
    632                                         return False;
    633                                 need_chown = False;
    634                         } else { /* chown is needed, but _after_ changing acl */
    635                                 sbuf.st_uid = newUID; /* OWNER@ in case of e_special */
    636                                 sbuf.st_gid = newGID; /* GROUP@ in case of e_special */
    637                         }
    638                 }
    639         }
    640 
    641         if ((security_info_sent & DACL_SECURITY_INFORMATION)!=0 && psd->dacl!=NULL)
    642         {
    643                 acl = smbacl4_win2nfs4(psd->dacl, &params, sbuf.st_uid, sbuf.st_gid);
    644                 if (!acl)
    645                         return False;
    646 
    647                 smbacl4_dump_nfs4acl(10, acl);
    648 
    649                 result = set_nfs4_native(fsp, acl);
    650                 if (result!=True)
    651                 {
    652                         DEBUG(10, ("set_nfs4_native failed with %s\n", strerror(errno)));
    653                         return False;
    654                 }
    655         } else
     621                        if(try_chown(fsp->conn, fsp->fsp_name, newUID, newGID)) {
     622                                DEBUG(3,("chown %s, %u, %u failed. Error = %s.\n",
     623                                        fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID, strerror(errno) ));
     624                                return False;
     625                        }
     626                        DEBUG(10,("chown %s, %u, %u succeeded.\n",
     627                                fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID));
     628                        if (smbacl4_GetFileOwner(fsp, &sbuf))
     629                                return False;
     630                        /* If we successfully chowned, we know we must
     631                         * be able to set the acl, so do it as root.
     632                         */
     633                        set_acl_as_root = True;
     634                }
     635        }
     636
     637        if (!(security_info_sent & DACL_SECURITY_INFORMATION) || psd->dacl ==NULL) {
    656638                DEBUG(10, ("no dacl found; security_info_sent = 0x%x\n", security_info_sent));
    657 
    658         /* Any chown pending? */
    659         if (need_chown) {
    660                 DEBUG(3,("chown#2 %s. uid = %u, gid = %u.\n",
    661                         fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID));
    662                 if (try_chown(fsp->conn, fsp->fsp_name, newUID, newGID)) {
    663                         DEBUG(2,("chown#2 %s, %u, %u failed. Error = %s.\n",
    664                                 fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID,
    665                                 strerror(errno)));
    666                         return False;
    667                 }
    668                 DEBUG(10,("chown#2 %s, %u, %u succeeded.\n",
    669                         fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID));
     639                return True;
     640        }
     641        acl = smbacl4_win2nfs4(psd->dacl, &params, sbuf.st_uid, sbuf.st_gid);
     642        if (!acl)
     643                return False;
     644
     645        smbacl4_dump_nfs4acl(10, acl);
     646
     647        if (set_acl_as_root) {
     648                become_root();
     649        }
     650        result = set_nfs4_native(fsp, acl);
     651        saved_errno = errno;
     652        if (set_acl_as_root) {
     653                unbecome_root();
     654        }
     655        if (result!=True) {
     656                errno = saved_errno;
     657                DEBUG(10, ("set_nfs4_native failed with %s\n", strerror(errno)));
     658                return False;
    670659        }
    671660
  • branches/samba-3.0/source/modules/vfs_default.c

    r124 r312  
    636636                times.actime = convert_timespec_to_time_t(ts[0]);
    637637                times.modtime = convert_timespec_to_time_t(ts[1]);
    638                 result = utime(path, times);
     638                result = utime(path, &times);
    639639        }
    640640#else
  • branches/samba-3.0/source/nsswitch/winbindd_passdb.c

    r165 r312  
    591591                        continue;
    592592                }
    593                 if (!((*names)[i] = talloc_strdup((*names),
     593                if (!((*names)[num_mapped] = talloc_strdup((*names),
    594594                                                  lsa_names[i].name))) {
    595595                        TALLOC_FREE(tmp_ctx);
     
    597597                }
    598598
    599                 (*name_types)[i] = lsa_names[i].type;
     599                (*name_types)[num_mapped] = lsa_names[i].type;
    600600
    601601                num_mapped += 1;
  • branches/samba-3.0/source/nsswitch/wins.c

    r1 r312  
    2525
    2626#include <ns_daemon.h>
     27#endif
     28
     29#if HAVE_PTHREAD_H
     30#include <pthread.h>
     31#endif
     32
     33#if HAVE_PTHREAD
     34static pthread_mutex_t wins_nss_mutex = PTHREAD_MUTEX_INITIALIZER;
    2735#endif
    2836
     
    298306                          char *buffer, size_t buflen, int *h_errnop)
    299307{
     308        NSS_STATUS nss_status = NSS_STATUS_SUCCESS;
    300309        struct in_addr *ip_list;
    301310        int i, count;
     
    303312        size_t namelen;
    304313               
     314#if HAVE_PTHREAD
     315        pthread_mutex_lock(&wins_nss_mutex);
     316#endif
     317
    305318        memset(he, '\0', sizeof(*he));
    306319        fstrcpy(name, hostname);
     
    310323        ip_list = lookup_byname_backend(name, &count);
    311324
    312         if (!ip_list)
    313                 return NSS_STATUS_NOTFOUND;
     325        if (!ip_list) {
     326                nss_status = NSS_STATUS_NOTFOUND;
     327                goto out;
     328        }
    314329
    315330        /* Copy h_name */
     
    317332        namelen = strlen(name) + 1;
    318333
    319         if ((he->h_name = get_static(&buffer, &buflen, namelen)) == NULL)
    320                 return NSS_STATUS_TRYAGAIN;
     334        if ((he->h_name = get_static(&buffer, &buflen, namelen)) == NULL) {
     335                nss_status = NSS_STATUS_TRYAGAIN;
     336                goto out;
     337        }
    321338
    322339        memcpy(he->h_name, name, namelen);
     
    327344                i = sizeof(char*) - i;
    328345
    329         if (get_static(&buffer, &buflen, i) == NULL)
    330                 return NSS_STATUS_TRYAGAIN;
     346        if (get_static(&buffer, &buflen, i) == NULL) {
     347                nss_status = NSS_STATUS_TRYAGAIN;
     348                goto out;
     349        }
    331350
    332351        if ((he->h_addr_list = (char **)get_static(
    333                      &buffer, &buflen, (count + 1) * sizeof(char *))) == NULL)
    334                 return NSS_STATUS_TRYAGAIN;
     352                     &buffer, &buflen, (count + 1) * sizeof(char *))) == NULL) {
     353                nss_status = NSS_STATUS_TRYAGAIN;
     354                goto out;
     355        }
    335356
    336357        for (i = 0; i < count; i++) {
    337358                if ((he->h_addr_list[i] = get_static(&buffer, &buflen,
    338                                                      INADDRSZ)) == NULL)
    339                         return NSS_STATUS_TRYAGAIN;
     359                                                     INADDRSZ)) == NULL) {
     360                        nss_status = NSS_STATUS_TRYAGAIN;
     361                        goto out;
     362                }
    340363                memcpy(he->h_addr_list[i], &ip_list[i], INADDRSZ);
    341364        }
     
    356379                i = sizeof(char*) - i;
    357380
    358         if (get_static(&buffer, &buflen, i) == NULL)
    359                 return NSS_STATUS_TRYAGAIN;
     381        if (get_static(&buffer, &buflen, i) == NULL) {
     382                nss_status = NSS_STATUS_TRYAGAIN;
     383                goto out;
     384        }
    360385
    361386        if ((he->h_aliases = (char **)get_static(
    362                      &buffer, &buflen, sizeof(char *))) == NULL)
    363                 return NSS_STATUS_TRYAGAIN;
     387                     &buffer, &buflen, sizeof(char *))) == NULL) {
     388                nss_status = NSS_STATUS_TRYAGAIN;
     389                goto out;
     390        }
    364391
    365392        he->h_aliases[0] = NULL;
    366393
    367         return NSS_STATUS_SUCCESS;
     394        nss_status = NSS_STATUS_SUCCESS;
     395
     396  out:
     397
     398#if HAVE_PTHREAD
     399        pthread_mutex_unlock(&wins_nss_mutex);
     400#endif
     401        return nss_status;
    368402}
    369403
     
    373407                           char *buffer, size_t buflen, int *h_errnop)
    374408{
     409        NSS_STATUS nss_status;
     410
     411#if HAVE_PTHREAD
     412        pthread_mutex_lock(&wins_nss_mutex);
     413#endif
     414
    375415        if(af!=AF_INET) {
    376416                *h_errnop = NO_DATA;
    377                 return NSS_STATUS_UNAVAIL;
    378         }
    379 
    380         return _nss_wins_gethostbyname_r(
    381                 name, he, buffer, buflen, h_errnop);
    382 }
    383 #endif
     417                nss_status = NSS_STATUS_UNAVAIL;
     418        } else {
     419                nss_status = _nss_wins_gethostbyname_r(
     420                                name, he, buffer, buflen, h_errnop);
     421        }
     422#if HAVE_PTHREAD
     423        pthread_mutex_unlock(&wins_nss_mutex);
     424#endif
     425        return nss_status;
     426}
     427#endif
  • branches/samba-3.0/source/param/loadparm.c

    r307 r312  
    151151        char *szPanicAction;
    152152        char *szAddUserScript;
    153         char *szRenameUserScript;
     153        char *szRenameUserScript;
    154154        char *szDelUserScript;
    155155        char *szAddGroupScript;
     
    188188        char *szChangeShareCommand;
    189189        char *szDeleteShareCommand;
    190         char **szEventLogs;
     190char **szEventLogs;
    191191        char *szGuestaccount;
    192192        char *szManglingMethod;
     
    472472        False,                  /* not autoloaded */
    473473        0,                      /* not a usershare */
    474         (time_t)0,              /* No last mod time */
     474        (time_t)0,            /* No last mod time */
    475475        NULL,                   /* szService */
    476476        NULL,                   /* szPath */
     
    513513        NULL,                   /* fstype */
    514514        NULL,                   /* vfs objects */
    515         NULL,                   /* szMSDfsProxy */
     515        NULL,              /* szMSDfsProxy */
    516516        NULL,                   /* szAioWriteBehind */
    517517        NULL,                   /* szDfree */
     
    533533        2,                      /* iOplockContentionLimit */
    534534        0,                      /* iCSCPolicy */
    535         1024,                   /* iBlock_size */
     535        1024,           /* iBlock_size */
    536536        0,                      /* iDfreeCacheTime */
    537537        False,                  /* bPreexecClose */
     
    588588        False,                  /* bForcePrintername */
    589589        True,                   /* bNTAclSupport */
    590         False,                  /* bForceUnknownAclUser */
     590        False,            /* bForceUnknownAclUser */
    591591        False,                  /* bUseSendfile */
    592592        False,                  /* bProfileAcls */
     
    821821        {MAP_TO_GUEST_ON_BAD_USER, "Bad User"},
    822822        {MAP_TO_GUEST_ON_BAD_PASSWORD, "Bad Password"},
    823         {MAP_TO_GUEST_ON_BAD_UID, "Bad Uid"},
     823        {MAP_TO_GUEST_ON_BAD_UID, "Bad Uid"},
    824824        {-1, NULL}
    825825};
     
    834834 *       Any parameter that does NOT have FLAG_ADVANCED will not disply at all
    835835 *       Set FLAG_SHARE and FLAG_PRINT to specifically display parameters in
    836  *        respective views.
     836 *      respective views.
    837837 *
    838838 * NOTE2: Handling of duplicated (synonym) paramters:
     
    11221122
    11231123        {"add user script", P_STRING, P_GLOBAL, &Globals.szAddUserScript, NULL, NULL, FLAG_ADVANCED},
    1124         {"rename user script", P_STRING, P_GLOBAL, &Globals.szRenameUserScript, NULL, NULL, FLAG_ADVANCED},
     1124        {"rename user script", P_STRING, P_GLOBAL, &Globals.szRenameUserScript, NULL, NULL, FLAG_ADVANCED},
    11251125        {"delete user script", P_STRING, P_GLOBAL, &Globals.szDelUserScript, NULL, NULL, FLAG_ADVANCED},
    11261126        {"add group script", P_STRING, P_GLOBAL, &Globals.szAddGroupScript, NULL, NULL, FLAG_ADVANCED},
     
    14181418        pstring s;
    14191419
    1420         /* If requested to initialize only once and we've already done it... */
    1421         if (first_time_only && done_init) {
    1422                 /* ... then we have nothing more to do */
    1423                 return;
    1424         }
     1420        /* If requested to initialize only once and we've already done it... */
     1421        if (first_time_only && done_init) {
     1422                /* ... then we have nothing more to do */
     1423                return;
     1424        }
    14251425
    14261426        if (!done_init) {
     
    14621462
    14631463#if defined (__OS2__)
    1464         /* search the system codepage and set OS2CodePageStr */
    1465         unsigned long _System DosQueryCp (unsigned long ulLength, unsigned long *pCodePageList, unsigned long *pDataLength);
    1466         pstring OS2CodePageStr;
    1467         unsigned long OS2CodePage[3];
    1468         unsigned long OS2CodePageLen;
    1469         if ( DosQueryCp( sizeof(OS2CodePage), OS2CodePage, &OS2CodePageLen ) )
    1470            slprintf(OS2CodePageStr, sizeof(OS2CodePageStr) -1, "SYSTEM");
    1471           else
    1472            slprintf(OS2CodePageStr, sizeof(OS2CodePageStr) -1, "IBM-%u", OS2CodePage[0]);
     1464        /* search the system codepage and set OS2CodePageStr */
     1465        unsigned long _System DosQueryCp (unsigned long ulLength, unsigned long *pCodePageList, unsigned long *pDataLength);
     1466        pstring OS2CodePageStr;
     1467        unsigned long OS2CodePage[3];
     1468        unsigned long OS2CodePageLen;
     1469        if ( DosQueryCp( sizeof(OS2CodePage), OS2CodePage, &OS2CodePageLen ) )
     1470                slprintf(OS2CodePageStr, sizeof(OS2CodePageStr) -1, "SYSTEM");
     1471        else
     1472                slprintf(OS2CodePageStr, sizeof(OS2CodePageStr) -1, "IBM-%u", OS2CodePage[0]);
    14731473#endif
    14741474
     
    14921492           characters - default to system codepage */
    14931493        string_set(&Globals.display_charset, OS2CodePageStr);
    1494 #endif 
     1494#endif
    14951495
    14961496#else
     
    22382238        BOOL global_section = False;
    22392239        char* param_key;
    2240         param_opt_struct *data;
     2240        param_opt_struct *data;
    22412241       
    22422242        if (snum >= iNumServices) return NULL;
     
    22682268                data = Globals.param_opt;
    22692269                while (data) {
    2270                         if (strcmp(data->key, param_key) == 0) {
    2271                                 string_free(&param_key);
     2270                        if (strcmp(data->key, param_key) == 0) {
     2271                                string_free(&param_key);
    22722272                                return data;
    22732273                        }
     
    24862486{
    24872487        int i;
    2488         param_opt_struct *data, *pdata;
     2488        param_opt_struct *data, *pdata;
    24892489        if (!pservice)
    24902490                return;
     
    26702670                DEBUG(10,("hash_a_service: creating tdb servicehash\n"));
    26712671                ServiceHash = tdb_open("servicehash", 1031, TDB_INTERNAL,
    2672                                         (O_RDWR|O_CREAT), 0600);
     2672                                        (O_RDWR|O_CREAT), 0600);
    26732673                if ( !ServiceHash ) {
    26742674                        DEBUG(0,("hash_a_service: open tdb servicehash failed!\n"));
     
    26832683                return False;
    26842684
    2685         tdb_store_int32(ServiceHash, canon_name, idx);
     2685        tdb_store_int32(ServiceHash, canon_name, idx);
    26862686
    26872687        return True;
  • branches/samba-3.0/source/rpc_server/srv_netlog_nt.c

    r134 r312  
    432432        DOM_CHAL srv_chal_out;
    433433
     434        /* According to Microsoft (see bugid #6099)
     435         * Windows 7 looks at the negotiate_flags
     436         * returned in this structure *even if the
     437         * call fails with access denied ! So in order
     438         * to allow Win7 to connect to a Samba NT style
     439         * PDC we set the flags before we know if it's
     440         * an error or not.
     441         */
     442
     443        srv_flgs.neg_flags = 0x000001ff;
     444
     445        if (lp_server_schannel() != False) {
     446                srv_flgs.neg_flags |= NETLOGON_NEG_SCHANNEL;
     447        }
     448
     449        /* set up the initial LSA AUTH 2 response */
     450        ZERO_STRUCT(srv_chal_out);
     451        init_net_r_auth_2(r_u, &srv_chal_out, &srv_flgs, NT_STATUS_OK);
     452
    434453        rpcstr_pull(mach_acct, q_u->clnt_id.uni_acct_name.buffer,sizeof(fstring),
    435454                                q_u->clnt_id.uni_acct_name.uni_str_len*2,0);
     
    480499        }
    481500
    482         srv_flgs.neg_flags = 0x000001ff;
    483 
    484         if (lp_server_schannel() != False) {
    485                 srv_flgs.neg_flags |= NETLOGON_NEG_SCHANNEL;
    486         }
    487 
    488         /* set up the LSA AUTH 2 response */
     501        /* set up the real LSA AUTH 2 response */
    489502        init_net_r_auth_2(r_u, &srv_chal_out, &srv_flgs, NT_STATUS_OK);
    490503
  • branches/samba-3.0/source/rpc_server/srv_pipe.c

    r1 r312  
    20632063        auth_len = p->hdr.auth_len;
    20642064
    2065         if (auth_len != RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN) {
     2065        if (auth_len < RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN ||
     2066                        auth_len > RPC_HEADER_LEN +
     2067                                        RPC_HDR_REQ_LEN +
     2068                                        RPC_HDR_AUTH_LEN +
     2069                                        auth_len) {
    20662070                DEBUG(0,("Incorrect auth_len %u.\n", (unsigned int)auth_len ));
    20672071                return False;
  • branches/samba-3.0/source/script/installman.sh

    r1 r312  
    2121# Get the configured feature set
    2222test -f "${SRCDIR}/config.log" && \
    23         eval `grep "^[[:alnum:]]*=.*" "${SRCDIR}/config.log"`
     23        eval `grep "^[[:alnum:]_]*=.*" "${SRCDIR}/config.log"`
    2424
    2525for lang in $langs; do
     
    4949            # Check if this man page if required by the configured feature set
    5050            case "${MP_BASENAME}" in
     51                cifs.upcall.8) test -z "${CIFSUPCALL_PROGS}" && continue ;;
    5152                smbsh.1) test -z "${SMBWRAPPER}" && continue ;;
    5253                smbmnt.8|smbmount.8|smbumount.8) test -z "${SMBMOUNT_PROGS}" && continue ;;
  • branches/samba-3.0/source/smbd/lanman.c

    r105 r312  
    11381138                        continue;
    11391139                }
    1140                 if (!next_token(&ptr,s->comment, NULL, sizeof(s->comment))) {
     1140                if (!next_token(&ptr,s->comment, NULL,
     1141                                MIN(sizeof(s->comment),
     1142                                    MAX_SERVER_STRING_LENGTH))) {
    11411143                        continue;
    11421144                }
  • branches/samba-3.0/source/smbd/posix_acls.c

    r286 r312  
    30983098        }
    30993099
     3100        /* only allow chown to the current user. This is more secure,
     3101           and also copes with the case where the SID in a take ownership ACL is
     3102           a local SID on the users workstation
     3103        */
     3104        if (uid != current_user.ut.uid) {
     3105                errno = EPERM;
     3106                return -1;
     3107        }
     3108
    31003109        if (SMB_VFS_STAT(conn,fname,&st)) {
    31013110                return -1;
     
    31053114                return -1;
    31063115        }
    3107 
    3108         /* only allow chown to the current user. This is more secure,
    3109            and also copes with the case where the SID in a take ownership ACL is
    3110            a local SID on the users workstation
    3111         */
    3112         uid = current_user.ut.uid;
    31133116
    31143117        become_root();
     
    33393342        BOOL acl_perms = False;
    33403343        mode_t orig_mode = (mode_t)0;
    3341         uid_t orig_uid;
    3342         gid_t orig_gid;
    3343         BOOL need_chown = False;
     3344        BOOL set_acl_as_root = false;
     3345        BOOL acl_set_support = false;
     3346        BOOL ret = false;
    33443347
    33453348        DEBUG(10,("set_nt_acl: called for file %s\n", fsp->fsp_name ));
     
    33643367        /* Save the original elements we check against. */
    33653368        orig_mode = sbuf.st_mode;
    3366         orig_uid = sbuf.st_uid;
    3367         orig_gid = sbuf.st_gid;
    33683369
    33693370        /*
     
    33793380         */
    33803381
    3381         if (((user != (uid_t)-1) && (orig_uid != user)) || (( grp != (gid_t)-1) && (orig_gid != grp))) {
    3382                 need_chown = True;
    3383         }
    3384 
    3385         /*
    3386          * Chown before setting ACL only if we don't change the user, or
    3387          * if we change to the current user, but not if we want to give away
    3388          * the file.
    3389          */
    3390 
    3391         if (need_chown && (user == (uid_t)-1 || user == current_user.ut.uid)) {
     3382        if (((user != (uid_t)-1) && (sbuf.st_uid != user)) || (( grp != (gid_t)-1) && (sbuf.st_gid != grp))) {
    33923383
    33933384                DEBUG(3,("set_nt_acl: chown %s. uid = %u, gid = %u.\n",
     
    34113402                } else {
    34123403
    3413                         int ret;
     3404                        int sret;
    34143405
    34153406                        if(fsp->fh->fd == -1)
    3416                                 ret = SMB_VFS_STAT(fsp->conn, fsp->fsp_name, &sbuf);
     3407                                sret = SMB_VFS_STAT(fsp->conn, fsp->fsp_name, &sbuf);
    34173408                        else
    3418                                 ret = SMB_VFS_FSTAT(fsp,fsp->fh->fd,&sbuf);
    3419 
    3420                         if(ret != 0)
     3409                                sret = SMB_VFS_FSTAT(fsp,fsp->fh->fd,&sbuf);
     3410
     3411                        if(sret != 0)
    34213412                                return False;
    34223413                }
     
    34243415                /* Save the original elements we check against. */
    34253416                orig_mode = sbuf.st_mode;
    3426                 orig_uid = sbuf.st_uid;
    3427                 orig_gid = sbuf.st_gid;
    3428 
    3429                 /* We did it, don't try again */
    3430                 need_chown = False;
     3417
     3418                /* If we successfully chowned, we know we must
     3419                 * be able to set the acl, so do it as root.
     3420                */
     3421                set_acl_as_root = true;
    34313422        }
    34323423
    34333424        create_file_sids(&sbuf, &file_owner_sid, &file_grp_sid);
    3434 
    3435 #if 0
    3436         /* Disable this - prevents ACL inheritance from the ACL editor. JRA. */
    3437 
    3438         /* See here: http://www.codeproject.com/KB/winsdk/accessctrl2.aspx
    3439          * for details and also the log trace in bug #4308. JRA.
    3440         */
    3441 
    3442         if ((security_info_sent & DACL_SECURITY_INFORMATION) &&
    3443                 psd->dacl != NULL &&
    3444                 (psd->type & (SE_DESC_DACL_AUTO_INHERITED|
    3445                               SE_DESC_DACL_AUTO_INHERIT_REQ))==
    3446                         (SE_DESC_DACL_AUTO_INHERITED|
    3447                          SE_DESC_DACL_AUTO_INHERIT_REQ) ) {
    3448                 NTSTATUS status = append_parent_acl(fsp, &sbuf, psd, &psd);
    3449                 if (!NT_STATUS_IS_OK(status)) {
    3450                         return False;
    3451                 }
    3452         }
    3453 #endif
    34543425
    34553426        acl_perms = unpack_canon_ace( fsp, &sbuf, &file_owner_sid, &file_grp_sid,
     
    34573428
    34583429        /* Ignore W2K traverse DACL set. */
    3459         if (file_ace_list || dir_ace_list) {
    3460 
    3461                 if (!acl_perms) {
    3462                         DEBUG(3,("set_nt_acl: cannot set permissions\n"));
     3430        if (!file_ace_list && !dir_ace_list) {
     3431                return True;
     3432        }
     3433
     3434        if (!acl_perms) {
     3435                DEBUG(3,("set_nt_acl: cannot set permissions\n"));
     3436                free_canon_ace_list(file_ace_list);
     3437                free_canon_ace_list(dir_ace_list);
     3438                return False;
     3439        }
     3440
     3441        /*
     3442         * Only change security if we got a DACL.
     3443         */
     3444
     3445        if(!(security_info_sent & DACL_SECURITY_INFORMATION) || (psd->dacl == NULL)) {
     3446                free_canon_ace_list(file_ace_list);
     3447                free_canon_ace_list(dir_ace_list);
     3448                return True;
     3449        }
     3450
     3451        /*
     3452         * Try using the POSIX ACL set first. Fall back to chmod if
     3453         * we have no ACL support on this filesystem.
     3454         */
     3455
     3456        if (acl_perms && file_ace_list) {
     3457                if (set_acl_as_root) {
     3458                        become_root();
     3459                }
     3460                ret = set_canon_ace_list(fsp, file_ace_list, False, sbuf.st_gid, &acl_set_support);
     3461                if (set_acl_as_root) {
     3462                        unbecome_root();
     3463                }
     3464                if (acl_set_support && ret == False) {
     3465                        DEBUG(3,("set_nt_acl: failed to set file acl on file %s (%s).\n", fsp->fsp_name, strerror(errno) ));
    34633466                        free_canon_ace_list(file_ace_list);
    3464                         free_canon_ace_list(dir_ace_list); 
     3467                        free_canon_ace_list(dir_ace_list);
    34653468                        return False;
    34663469                }
    3467 
    3468                 /*
    3469                  * Only change security if we got a DACL.
    3470                  */
    3471 
    3472                 if((security_info_sent & DACL_SECURITY_INFORMATION) && (psd->dacl != NULL)) {
    3473 
    3474                         BOOL acl_set_support = False;
    3475                         BOOL ret = False;
     3470        }
     3471
     3472        if (acl_perms && acl_set_support && fsp->is_directory) {
     3473                if (dir_ace_list) {
     3474                        if (set_acl_as_root) {
     3475                                become_root();
     3476                        }
     3477                        ret = set_canon_ace_list(fsp, dir_ace_list, True, sbuf.st_gid, &acl_set_support);
     3478                        if (set_acl_as_root) {
     3479                                unbecome_root();
     3480                        }
     3481                        if (ret == False) {
     3482                                DEBUG(3,("set_nt_acl: failed to set default acl on directory %s (%s).\n", fsp->fsp_name, strerror(errno) ));
     3483                                free_canon_ace_list(file_ace_list);
     3484                                free_canon_ace_list(dir_ace_list);
     3485                                return False;
     3486                        }
     3487                } else {
     3488
     3489                        int sret = -1;
    34763490
    34773491                        /*
    3478                          * Try using the POSIX ACL set first. Fall back to chmod if
    3479                          * we have no ACL support on this filesystem.
     3492                         * No default ACL - delete one if it exists.
    34803493                         */
    34813494
    3482                         if (acl_perms && file_ace_list) {
    3483                                 ret = set_canon_ace_list(fsp, file_ace_list, False, sbuf.st_gid, &acl_set_support);
    3484                                 if (acl_set_support && ret == False) {
    3485                                         DEBUG(3,("set_nt_acl: failed to set file acl on file %s (%s).\n", fsp->fsp_name, strerror(errno) ));
     3495                        if (set_acl_as_root) {
     3496                                become_root();
     3497                        }
     3498                        sret = SMB_VFS_SYS_ACL_DELETE_DEF_FILE(conn, fsp->fsp_name);
     3499                        if (set_acl_as_root) {
     3500                                unbecome_root();
     3501                        }
     3502
     3503                        if (sret == -1) {
     3504                                if (acl_group_override(conn, sbuf.st_gid, fsp->fsp_name)) {
     3505                                        DEBUG(5,("set_nt_acl: acl group control on and "
     3506                                                "current user in file %s primary group. Override delete_def_acl\n",
     3507                                                fsp->fsp_name ));
     3508
     3509                                        become_root();
     3510                                        sret = SMB_VFS_SYS_ACL_DELETE_DEF_FILE(conn, fsp->fsp_name);
     3511                                        unbecome_root();
     3512                                }
     3513
     3514                                if (sret == -1) {
     3515                                        DEBUG(3,("set_nt_acl: sys_acl_delete_def_file failed (%s)\n", strerror(errno)));
    34863516                                        free_canon_ace_list(file_ace_list);
    3487                                         free_canon_ace_list(dir_ace_list); 
     3517                                        free_canon_ace_list(dir_ace_list);
    34883518                                        return False;
    34893519                                }
    34903520                        }
    3491 
    3492                         if (acl_perms && acl_set_support && fsp->is_directory) {
    3493                                 if (dir_ace_list) {
    3494                                         if (!set_canon_ace_list(fsp, dir_ace_list, True, sbuf.st_gid, &acl_set_support)) {
    3495                                                 DEBUG(3,("set_nt_acl: failed to set default acl on directory %s (%s).\n", fsp->fsp_name, strerror(errno) ));
    3496                                                 free_canon_ace_list(file_ace_list);
    3497                                                 free_canon_ace_list(dir_ace_list);
    3498                                                 return False;
    3499                                         }
    3500                                 } else {
    3501 
    3502                                         /*
    3503                                          * No default ACL - delete one if it exists.
    3504                                          */
    3505 
    3506                                         if (SMB_VFS_SYS_ACL_DELETE_DEF_FILE(conn, fsp->fsp_name) == -1) {
    3507                                                 int sret = -1;
    3508 
    3509                                                 if (acl_group_override(conn, sbuf.st_gid, fsp->fsp_name)) {
    3510                                                         DEBUG(5,("set_nt_acl: acl group control on and "
    3511                                                                 "current user in file %s primary group. Override delete_def_acl\n",
    3512                                                                 fsp->fsp_name ));
    3513 
    3514                                                         become_root();
    3515                                                         sret = SMB_VFS_SYS_ACL_DELETE_DEF_FILE(conn, fsp->fsp_name);
    3516                                                         unbecome_root();
    3517                                                 }
    3518 
    3519                                                 if (sret == -1) {
    3520                                                         DEBUG(3,("set_nt_acl: sys_acl_delete_def_file failed (%s)\n", strerror(errno)));
    3521                                                         free_canon_ace_list(file_ace_list);
    3522                                                         free_canon_ace_list(dir_ace_list);
    3523                                                         return False;
    3524                                                 }
    3525                                         }
     3521                }
     3522        }
     3523
     3524        if (acl_set_support) {
     3525                if (set_acl_as_root) {
     3526                        become_root();
     3527                }
     3528                store_inheritance_attributes(fsp, file_ace_list, dir_ace_list,
     3529                                (psd->type & SE_DESC_DACL_PROTECTED) ? True : False);
     3530                if (set_acl_as_root) {
     3531                        unbecome_root();
     3532                }
     3533        }
     3534
     3535        /*
     3536         * If we cannot set using POSIX ACLs we fall back to checking if we need to chmod.
     3537         */
     3538
     3539        if(!acl_set_support && acl_perms) {
     3540                mode_t posix_perms;
     3541
     3542                if (!convert_canon_ace_to_posix_perms( fsp, file_ace_list, &posix_perms)) {
     3543                        free_canon_ace_list(file_ace_list);
     3544                        free_canon_ace_list(dir_ace_list);
     3545                        DEBUG(3,("set_nt_acl: failed to convert file acl to posix permissions for file %s.\n",
     3546                                fsp->fsp_name ));
     3547                        return False;
     3548                }
     3549
     3550                if (orig_mode != posix_perms) {
     3551                        int sret = -1;
     3552
     3553                        DEBUG(3,("set_nt_acl: chmod %s. perms = 0%o.\n",
     3554                                fsp->fsp_name, (unsigned int)posix_perms ));
     3555
     3556                        if (set_acl_as_root) {
     3557                                become_root();
     3558                        }
     3559                        sret = SMB_VFS_CHMOD(conn,fsp->fsp_name, posix_perms);
     3560                        if (set_acl_as_root) {
     3561                                unbecome_root();
     3562                        }
     3563                        if(sret == -1) {
     3564                                if (acl_group_override(conn, sbuf.st_gid, fsp->fsp_name)) {
     3565                                        DEBUG(5,("set_nt_acl: acl group control on and "
     3566                                                "current user in file %s primary group. Override chmod\n",
     3567                                                fsp->fsp_name ));
     3568
     3569                                        become_root();
     3570                                        sret = SMB_VFS_CHMOD(conn,fsp->fsp_name, posix_perms);
     3571                                        unbecome_root();
    35263572                                }
    3527                         }
    3528 
    3529                         if (acl_set_support) {
    3530                                 store_inheritance_attributes(fsp, file_ace_list, dir_ace_list,
    3531                                                 (psd->type & SE_DESC_DACL_PROTECTED) ? True : False);
    3532                         }
    3533 
    3534                         /*
    3535                          * If we cannot set using POSIX ACLs we fall back to checking if we need to chmod.
    3536                          */
    3537 
    3538                         if(!acl_set_support && acl_perms) {
    3539                                 mode_t posix_perms;
    3540 
    3541                                 if (!convert_canon_ace_to_posix_perms( fsp, file_ace_list, &posix_perms)) {
     3573
     3574                                if (sret == -1) {
     3575                                        DEBUG(3,("set_nt_acl: chmod %s, 0%o failed. Error = %s.\n",
     3576                                                fsp->fsp_name, (unsigned int)posix_perms, strerror(errno) ));
    35423577                                        free_canon_ace_list(file_ace_list);
    35433578                                        free_canon_ace_list(dir_ace_list);
    3544                                         DEBUG(3,("set_nt_acl: failed to convert file acl to posix permissions for file %s.\n",
    3545                                                 fsp->fsp_name ));
    35463579                                        return False;
    35473580                                }
    3548 
    3549                                 if (orig_mode != posix_perms) {
    3550 
    3551                                         DEBUG(3,("set_nt_acl: chmod %s. perms = 0%o.\n",
    3552                                                 fsp->fsp_name, (unsigned int)posix_perms ));
    3553 
    3554                                         if(SMB_VFS_CHMOD(conn,fsp->fsp_name, posix_perms) == -1) {
    3555                                                 int sret = -1;
    3556                                                 if (acl_group_override(conn, sbuf.st_gid, fsp->fsp_name)) {
    3557                                                         DEBUG(5,("set_nt_acl: acl group control on and "
    3558                                                                 "current user in file %s primary group. Override chmod\n",
    3559                                                                 fsp->fsp_name ));
    3560 
    3561                                                         become_root();
    3562                                                         sret = SMB_VFS_CHMOD(conn,fsp->fsp_name, posix_perms);
    3563                                                         unbecome_root();
    3564                                                 }
    3565 
    3566                                                 if (sret == -1) {
    3567                                                         DEBUG(3,("set_nt_acl: chmod %s, 0%o failed. Error = %s.\n",
    3568                                                                 fsp->fsp_name, (unsigned int)posix_perms, strerror(errno) ));
    3569                                                         free_canon_ace_list(file_ace_list);
    3570                                                         free_canon_ace_list(dir_ace_list);
    3571                                                         return False;
    3572                                                 }
    3573                                         }
    3574                                 }
    3575                         }
    3576                 }
    3577 
    3578                 free_canon_ace_list(file_ace_list);
    3579                 free_canon_ace_list(dir_ace_list);
    3580         }
    3581 
    3582         /* Any chown pending? */
    3583         if (need_chown) {
    3584 
    3585                 DEBUG(3,("set_nt_acl: chown %s. uid = %u, gid = %u.\n",
    3586                         fsp->fsp_name, (unsigned int)user, (unsigned int)grp ));
    3587 
    3588                 if(try_chown( fsp->conn, fsp->fsp_name, user, grp) == -1) {
    3589                         DEBUG(3,("set_nt_acl: chown %s, %u, %u failed. Error = %s.\n",
    3590                                 fsp->fsp_name, (unsigned int)user, (unsigned int)grp, strerror(errno) ));
    3591                         return False;
    3592                 }
    3593         }
    3594 
     3581                        }
     3582                }
     3583        }
     3584
     3585        free_canon_ace_list(file_ace_list);
     3586        free_canon_ace_list(dir_ace_list);
    35953587        return True;
    35963588}
     
    39693961        SMB_ACL_T def_acl = NULL;
    39703962
    3971         if (num_def_acls && !S_ISDIR(psbuf->st_mode)) {
    3972                 DEBUG(5,("set_unix_posix_default_acl: Can't set default ACL on non-directory file %s\n", fname ));
    3973                 errno = EISDIR;
    3974                 return False;
     3963        if (!S_ISDIR(psbuf->st_mode)) {
     3964                if (num_def_acls) {
     3965                        DEBUG(5,("set_unix_posix_default_acl: Can't set default ACL on non-directory file %s\n", fname ));
     3966                        errno = EISDIR;
     3967                        return false;
     3968                } else {
     3969                        return true;
     3970                }
    39753971        }
    39763972
  • branches/samba-3.0/source/smbd/server.c

    r165 r312  
    11201120
    11211121        if (*lp_rootdir()) {
    1122                 if (sys_chroot(lp_rootdir()) == 0)
    1123                         DEBUG(2,("Changed root to %s\n", lp_rootdir()));
     1122                if (sys_chroot(lp_rootdir()) != 0) {
     1123                        DEBUG(0,("Failed to change root to %s\n", lp_rootdir()));
     1124                        exit(1);
     1125                }
     1126                if (chdir("/") == -1) {
     1127                        DEBUG(0,("Failed to chdir to / on chroot to %s\n", lp_rootdir()));
     1128                        exit(1);
     1129                }
     1130                DEBUG(0,("Changed root to %s\n", lp_rootdir()));
    11241131        }
    11251132
  • branches/samba-3.0/source/smbd/trans2.c

    r165 r312  
    54825482        } else if((wire_open_mode & SMB_O_CREAT) == SMB_O_CREAT) {
    54835483                create_disp = FILE_OPEN_IF;
     5484        } else if ((wire_open_mode & (SMB_O_CREAT | SMB_O_EXCL | SMB_O_TRUNC)) == 0) {
     5485                create_disp = FILE_OPEN;
    54845486        } else {
    54855487                DEBUG(5,("smb_posix_open: invalid create mode 0x%x\n",
Note: See TracChangeset for help on using the changeset viewer.