Ignore:
Timestamp:
Mar 12, 2008, 9:08:18 AM (17 years ago)
Author:
Paul Smedley
Message:

Update source to 3.0.28a

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.0/source/client/mount.cifs.c

    r39 r124  
    8181char * prefixpath = NULL;
    8282
     83/* glibc doesn't have strlcpy, strlcat. Ensure we do. JRA. We
     84 * don't link to libreplace so need them here. */
     85
     86/* like strncpy but does not 0 fill the buffer and always null
     87 *    terminates. bufsize is the size of the destination buffer */
     88size_t strlcpy(char *d, const char *s, size_t bufsize)
     89{
     90        size_t len = strlen(s);
     91        size_t ret = len;
     92        if (bufsize <= 0) return 0;
     93        if (len >= bufsize) len = bufsize-1;
     94        memcpy(d, s, len);
     95        d[len] = 0;
     96        return ret;
     97}
     98
     99/* like strncat but does not 0 fill the buffer and always null
     100 *    terminates. bufsize is the length of the buffer, which should
     101 *       be one more than the maximum resulting string length */
     102size_t strlcat(char *d, const char *s, size_t bufsize)
     103{
     104        size_t len1 = strlen(d);
     105        size_t len2 = strlen(s);
     106        size_t ret = len1 + len2;
     107
     108        if (len1+len2 >= bufsize) {
     109                len2 = bufsize - (len1+1);
     110        }
     111        if (len2 > 0) {
     112                memcpy(d+len1, s, len2);
     113                d[len1+len2] = 0;
     114        }
     115        return ret;
     116}
    83117
    84118/* BB finish BB
     
    170204                                temp_val++;
    171205                                for(length = 0;length<4087;length++) {
    172                                         if(temp_val[length] == '\n')
     206                                        if ((temp_val[length] == '\n')
     207                                            || (temp_val[length] == '\0')) {
    173208                                                break;
     209                                        }
    174210                                }
    175211                                if(length > 4086) {
     
    194230                                temp_val++;
    195231                                for(length = 0;length<65;length++) {
    196                                         if(temp_val[length] == '\n')
     232                                        if ((temp_val[length] == '\n')
     233                                            || (temp_val[length] == '\0')) {
    197234                                                break;
     235                                        }
    198236                                }
    199237                                if(length > 64) {
     
    223261                                        printf("\nDomain %s\n",temp_val);
    224262                                for(length = 0;length<65;length++) {
    225                                         if(temp_val[length] == '\n')
    226                                                 break;
     263                                        if ((temp_val[length] == '\n')
     264                                            || (temp_val[length] == '\0')) {
     265                                                break;
     266                                        }
    227267                                }
    228268                                if(length > 64) {
     
    322362        int word_len;
    323363        int rc = 0;
     364        char user[32];
     365        char group[32];
    324366
    325367        if (!optionsp || !*optionsp)
     
    331373
    332374        /* BB fixme check for separator override BB */
     375
     376        if (getuid()) {
     377                got_uid = 1;
     378                snprintf(user,sizeof(user),"%u",getuid());
     379                got_gid = 1;
     380                snprintf(group,sizeof(group),"%u",getgid());
     381        }
    333382
    334383/* while ((data = strsep(&options, ",")) != NULL) { */
     
    494543                                if (!isdigit(*value)) {
    495544                                        struct passwd *pw;
    496                                         static char temp[32];
    497545
    498546                                        if (!(pw = getpwnam(value))) {
     
    500548                                                exit(1);
    501549                                        }
    502                                         sprintf(temp, "%u", pw->pw_uid);
    503                                         value = temp;
    504                                         endpwent();
    505                                 }
    506                         }
     550                                        snprintf(user, sizeof(user), "%u", pw->pw_uid);
     551                                } else {
     552                                        strlcpy(user,value,sizeof(user));
     553                                }
     554                        }
     555                        goto nocopy;
    507556                } else if (strncmp(data, "gid", 3) == 0) {
    508557                        if (value && *value) {
     
    510559                                if (!isdigit(*value)) {
    511560                                        struct group *gr;
    512                                         static char temp[32];
    513561
    514562                                        if (!(gr = getgrnam(value))) {
     
    516564                                                exit(1);
    517565                                        }
    518                                         sprintf(temp, "%u", gr->gr_gid);
    519                                         value = temp;
    520                                         endpwent();
    521                                 }
    522                         }
     566                                        snprintf(group, sizeof(group), "%u", gr->gr_gid);
     567                                } else {
     568                                        strlcpy(group,value,sizeof(group));
     569                                }
     570                        }
     571                        goto nocopy;
    523572       /* fmask and dmask synonyms for people used to smbfs syntax */
    524573                } else if (strcmp(data, "file_mode") == 0 || strcmp(data, "fmask")==0) {
     
    611660                }
    612661
    613                 if (out_len)
    614                         out[out_len++] = ',';
     662                if (out_len) {
     663                        strlcat(out, ",", out_len + word_len + 2);
     664                        out_len++;
     665                }
     666
    615667                if (value)
    616                         sprintf(out + out_len, "%s=%s", data, value);
     668                        snprintf(out + out_len, word_len + 1, "%s=%s", data, value);
    617669                else
    618                         sprintf(out + out_len, "%s", data);
     670                        snprintf(out + out_len, word_len + 1, "%s", data);
    619671                out_len = strlen(out);
    620672
     
    622674                data = next_keyword;
    623675        }
     676
     677        /* special-case the uid and gid */
     678        if (got_uid) {
     679                word_len = strlen(user);
     680
     681                out = (char *)realloc(out, out_len + word_len + 6);
     682                if (out == NULL) {
     683                        perror("malloc");
     684                        exit(1);
     685                }
     686
     687                if (out_len) {
     688                        strlcat(out, ",", out_len + word_len + 6);
     689                        out_len++;
     690                }
     691                snprintf(out + out_len, word_len + 5, "uid=%s", user);
     692                out_len = strlen(out);
     693        }
     694        if (got_gid) {
     695                word_len = strlen(group);
     696
     697                out = (char *)realloc(out, out_len + 1 + word_len + 6);
     698                if (out == NULL) {
     699                perror("malloc");
     700                        exit(1);
     701                }
     702
     703                if (out_len) {
     704                        strlcat(out, ",", out_len + word_len + 6);
     705                        out_len++;
     706                }
     707                snprintf(out + out_len, word_len + 5, "gid=%s", group);
     708                out_len = strlen(out);
     709        }
     710
    624711        free(*optionsp);
    625712        *optionsp = out;
     
    724811                return NULL;
    725812
    726         strcpy(domainnm,*ppuser);
     813        strlcpy(domainnm,*ppuser,len+1);
    727814
    728815/*      move_string(*ppuser, usernm+1) */
     
    895982        int optlen = 0;
    896983        int orgoptlen = 0;
     984        size_t options_size = 0;
    897985        int retry = 0; /* set when we have to retry mount with uppercase */
    898986        struct stat statbuf;
     
    11641252        if(options)
    11651253                free(options);
    1166         options = (char *)malloc(optlen + 10 + 64 /* space for commas in password */ + 8 /* space for domain=  , domain name itself was counted as part of the length username string above */);
     1254        options_size = optlen + 10 + 64;
     1255        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 */);
    11671256
    11681257        if(options == NULL) {
     
    11701259                return -1;
    11711260        }
    1172                
    11731261
    11741262        options[0] = 0;
    1175         strncat(options,"unc=",4);
    1176         strcat(options,share_name);
     1263        strlcpy(options,"unc=",options_size);
     1264        strlcat(options,share_name,options_size);
    11771265        /* scan backwards and reverse direction of slash */
    11781266        temp = strrchr(options, '/');
     
    11801268                *temp = '\\';
    11811269        if(ipaddr) {
    1182                 strncat(options,",ip=",4);
    1183                 strcat(options,ipaddr);
     1270                strlcat(options,",ip=",options_size);
     1271                strlcat(options,ipaddr,options_size);
    11841272        }
    11851273
     
    11881276                if(got_domain == 0)
    11891277                        domain_name = check_for_domain(&user_name);
    1190                 strncat(options,",user=",6);
    1191                 strcat(options,user_name);
     1278                strlcat(options,",user=",options_size);
     1279                strlcat(options,user_name,options_size);
    11921280        }
    11931281        if(retry == 0) {
    1194                 if(domain_name) { 
     1282                if(domain_name) {
    11951283                        /* extra length accounted for in option string above */
    1196                         strncat(options,",domain=",8);
    1197                         strcat(options,domain_name);
     1284                        strlcat(options,",domain=",options_size);
     1285                        strlcat(options,domain_name,options_size);
    11981286                }
    11991287        }
     
    12041292                if(retry == 0)
    12051293                        check_for_comma(&mountpassword);
    1206                 strncat(options,",pass=",6);
    1207                 strcat(options,mountpassword);
    1208         }
    1209 
    1210         strncat(options,",ver=",5);
    1211         strcat(options,MOUNT_CIFS_VERSION_MAJOR);
     1294                strlcat(options,",pass=",options_size);
     1295                strlcat(options,mountpassword,options_size);
     1296        }
     1297
     1298        strlcat(options,",ver=",options_size);
     1299        strlcat(options,MOUNT_CIFS_VERSION_MAJOR,options_size);
    12121300
    12131301        if(orgoptions) {
    1214                 strcat(options,",");
    1215                 strcat(options,orgoptions);
     1302                strlcat(options,",",options_size);
     1303                strlcat(options,orgoptions,options_size);
    12161304        }
    12171305        if(prefixpath) {
    1218                 strncat(options,",prefixpath=",12);
    1219                 strcat(options,prefixpath); /* no need to cat the / */
    1220         }       
     1306                strlcat(options,",prefixpath=",options_size);
     1307                strlcat(options,prefixpath,options_size); /* no need to cat the / */
     1308        }
    12211309        if(verboseflag)
    12221310                printf("\nmount.cifs kernel mount options %s \n",options);
     
    12621350                                memset(mountent.mnt_opts,0,200);
    12631351                                if(flags & MS_RDONLY)
    1264                                         strcat(mountent.mnt_opts,"ro");
     1352                                        strlcat(mountent.mnt_opts,"ro",220);
    12651353                                else
    1266                                         strcat(mountent.mnt_opts,"rw");
     1354                                        strlcat(mountent.mnt_opts,"rw",220);
    12671355                                if(flags & MS_MANDLOCK)
    1268                                         strcat(mountent.mnt_opts,",mand");
     1356                                        strlcat(mountent.mnt_opts,",mand",220);
    12691357                                if(flags & MS_NOEXEC)
    1270                                         strcat(mountent.mnt_opts,",noexec");
     1358                                        strlcat(mountent.mnt_opts,",noexec",220);
    12711359                                if(flags & MS_NOSUID)
    1272                                         strcat(mountent.mnt_opts,",nosuid");
     1360                                        strlcat(mountent.mnt_opts,",nosuid",220);
    12731361                                if(flags & MS_NODEV)
    1274                                         strcat(mountent.mnt_opts,",nodev");
     1362                                        strlcat(mountent.mnt_opts,",nodev",220);
    12751363                                if(flags & MS_SYNCHRONOUS)
    1276                                         strcat(mountent.mnt_opts,",synch");
     1364                                        strlcat(mountent.mnt_opts,",synch",220);
    12771365                                if(mount_user) {
    12781366                                        if(getuid() != 0) {
    1279                                                 strcat(mountent.mnt_opts,",user=");
    1280                                                 strcat(mountent.mnt_opts,mount_user);
     1367                                                strlcat(mountent.mnt_opts,",user=",220);
     1368                                                strlcat(mountent.mnt_opts,mount_user,220);
    12811369                                        }
    12821370                                        /* free(mount_user); do not free static mem */
     
    13191407        return rc;
    13201408}
    1321 
Note: See TracChangeset for help on using the changeset viewer.