Changeset 124 for branches/samba-3.0/source/client/mount.cifs.c
- Timestamp:
- Mar 12, 2008, 9:08:18 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.0/source/client/mount.cifs.c
r39 r124 81 81 char * prefixpath = NULL; 82 82 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 */ 88 size_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 */ 102 size_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 } 83 117 84 118 /* BB finish BB … … 170 204 temp_val++; 171 205 for(length = 0;length<4087;length++) { 172 if(temp_val[length] == '\n') 206 if ((temp_val[length] == '\n') 207 || (temp_val[length] == '\0')) { 173 208 break; 209 } 174 210 } 175 211 if(length > 4086) { … … 194 230 temp_val++; 195 231 for(length = 0;length<65;length++) { 196 if(temp_val[length] == '\n') 232 if ((temp_val[length] == '\n') 233 || (temp_val[length] == '\0')) { 197 234 break; 235 } 198 236 } 199 237 if(length > 64) { … … 223 261 printf("\nDomain %s\n",temp_val); 224 262 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 } 227 267 } 228 268 if(length > 64) { … … 322 362 int word_len; 323 363 int rc = 0; 364 char user[32]; 365 char group[32]; 324 366 325 367 if (!optionsp || !*optionsp) … … 331 373 332 374 /* 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 } 333 382 334 383 /* while ((data = strsep(&options, ",")) != NULL) { */ … … 494 543 if (!isdigit(*value)) { 495 544 struct passwd *pw; 496 static char temp[32];497 545 498 546 if (!(pw = getpwnam(value))) { … … 500 548 exit(1); 501 549 } 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; 507 556 } else if (strncmp(data, "gid", 3) == 0) { 508 557 if (value && *value) { … … 510 559 if (!isdigit(*value)) { 511 560 struct group *gr; 512 static char temp[32];513 561 514 562 if (!(gr = getgrnam(value))) { … … 516 564 exit(1); 517 565 } 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; 523 572 /* fmask and dmask synonyms for people used to smbfs syntax */ 524 573 } else if (strcmp(data, "file_mode") == 0 || strcmp(data, "fmask")==0) { … … 611 660 } 612 661 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 615 667 if (value) 616 s printf(out + out_len, "%s=%s", data, value);668 snprintf(out + out_len, word_len + 1, "%s=%s", data, value); 617 669 else 618 s printf(out + out_len, "%s", data);670 snprintf(out + out_len, word_len + 1, "%s", data); 619 671 out_len = strlen(out); 620 672 … … 622 674 data = next_keyword; 623 675 } 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 624 711 free(*optionsp); 625 712 *optionsp = out; … … 724 811 return NULL; 725 812 726 str cpy(domainnm,*ppuser);813 strlcpy(domainnm,*ppuser,len+1); 727 814 728 815 /* move_string(*ppuser, usernm+1) */ … … 895 982 int optlen = 0; 896 983 int orgoptlen = 0; 984 size_t options_size = 0; 897 985 int retry = 0; /* set when we have to retry mount with uppercase */ 898 986 struct stat statbuf; … … 1164 1252 if(options) 1165 1253 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 */); 1167 1256 1168 1257 if(options == NULL) { … … 1170 1259 return -1; 1171 1260 } 1172 1173 1261 1174 1262 options[0] = 0; 1175 str ncat(options,"unc=",4);1176 str cat(options,share_name);1263 strlcpy(options,"unc=",options_size); 1264 strlcat(options,share_name,options_size); 1177 1265 /* scan backwards and reverse direction of slash */ 1178 1266 temp = strrchr(options, '/'); … … 1180 1268 *temp = '\\'; 1181 1269 if(ipaddr) { 1182 str ncat(options,",ip=",4);1183 str cat(options,ipaddr);1270 strlcat(options,",ip=",options_size); 1271 strlcat(options,ipaddr,options_size); 1184 1272 } 1185 1273 … … 1188 1276 if(got_domain == 0) 1189 1277 domain_name = check_for_domain(&user_name); 1190 str ncat(options,",user=",6);1191 str cat(options,user_name);1278 strlcat(options,",user=",options_size); 1279 strlcat(options,user_name,options_size); 1192 1280 } 1193 1281 if(retry == 0) { 1194 if(domain_name) { 1282 if(domain_name) { 1195 1283 /* extra length accounted for in option string above */ 1196 str ncat(options,",domain=",8);1197 str cat(options,domain_name);1284 strlcat(options,",domain=",options_size); 1285 strlcat(options,domain_name,options_size); 1198 1286 } 1199 1287 } … … 1204 1292 if(retry == 0) 1205 1293 check_for_comma(&mountpassword); 1206 str ncat(options,",pass=",6);1207 str cat(options,mountpassword);1208 } 1209 1210 str ncat(options,",ver=",5);1211 str cat(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); 1212 1300 1213 1301 if(orgoptions) { 1214 str cat(options,",");1215 str cat(options,orgoptions);1302 strlcat(options,",",options_size); 1303 strlcat(options,orgoptions,options_size); 1216 1304 } 1217 1305 if(prefixpath) { 1218 str ncat(options,",prefixpath=",12);1219 str cat(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 } 1221 1309 if(verboseflag) 1222 1310 printf("\nmount.cifs kernel mount options %s \n",options); … … 1262 1350 memset(mountent.mnt_opts,0,200); 1263 1351 if(flags & MS_RDONLY) 1264 str cat(mountent.mnt_opts,"ro");1352 strlcat(mountent.mnt_opts,"ro",220); 1265 1353 else 1266 str cat(mountent.mnt_opts,"rw");1354 strlcat(mountent.mnt_opts,"rw",220); 1267 1355 if(flags & MS_MANDLOCK) 1268 str cat(mountent.mnt_opts,",mand");1356 strlcat(mountent.mnt_opts,",mand",220); 1269 1357 if(flags & MS_NOEXEC) 1270 str cat(mountent.mnt_opts,",noexec");1358 strlcat(mountent.mnt_opts,",noexec",220); 1271 1359 if(flags & MS_NOSUID) 1272 str cat(mountent.mnt_opts,",nosuid");1360 strlcat(mountent.mnt_opts,",nosuid",220); 1273 1361 if(flags & MS_NODEV) 1274 str cat(mountent.mnt_opts,",nodev");1362 strlcat(mountent.mnt_opts,",nodev",220); 1275 1363 if(flags & MS_SYNCHRONOUS) 1276 str cat(mountent.mnt_opts,",synch");1364 strlcat(mountent.mnt_opts,",synch",220); 1277 1365 if(mount_user) { 1278 1366 if(getuid() != 0) { 1279 str cat(mountent.mnt_opts,",user=");1280 str cat(mountent.mnt_opts,mount_user);1367 strlcat(mountent.mnt_opts,",user=",220); 1368 strlcat(mountent.mnt_opts,mount_user,220); 1281 1369 } 1282 1370 /* free(mount_user); do not free static mem */ … … 1319 1407 return rc; 1320 1408 } 1321
Note:
See TracChangeset
for help on using the changeset viewer.