Changeset 228 for branches/samba-3.2.x/source/client/mount.cifs.c
- Timestamp:
- May 26, 2009, 9:44:50 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.2.x/source/client/mount.cifs.c
r204 r228 40 40 #include <fcntl.h> 41 41 #include <limits.h> 42 #include "mount.h" 42 43 43 44 #define MOUNT_CIFS_VERSION_MAJOR "1" 44 #define MOUNT_CIFS_VERSION_MINOR "1 1"45 #define MOUNT_CIFS_VERSION_MINOR "12" 45 46 46 47 #ifndef MOUNT_CIFS_VENDOR_SUFFIX … … 56 57 #endif /* _SAMBA_BUILD_ */ 57 58 #endif /* MOUNT_CIFS_VENDOR_SUFFIX */ 59 60 #ifdef _SAMBA_BUILD_ 61 #include "include/config.h" 62 #endif 58 63 59 64 #ifndef MS_MOVE … … 95 100 /* like strncpy but does not 0 fill the buffer and always null 96 101 * terminates. bufsize is the size of the destination buffer */ 102 103 #ifndef HAVE_STRLCPY 97 104 static size_t strlcpy(char *d, const char *s, size_t bufsize) 98 105 { … … 105 112 return ret; 106 113 } 114 #endif 107 115 108 116 /* like strncat but does not 0 fill the buffer and always null 109 117 * terminates. bufsize is the length of the buffer, which should 110 118 * be one more than the maximum resulting string length */ 119 120 #ifndef HAVE_STRLCAT 111 121 static size_t strlcat(char *d, const char *s, size_t bufsize) 112 122 { … … 127 137 return ret; 128 138 } 139 #endif 129 140 130 141 /* BB finish BB … … 165 176 166 177 SAFE_FREE(mountpassword); 167 exit( 1);178 exit(EX_USAGE); 168 179 } 169 180 … … 224 235 printf("mount.cifs failed due to malformed username in credentials file"); 225 236 memset(line_buf,0,4096); 226 exit( 1);237 exit(EX_USAGE); 227 238 } else { 228 239 got_user = 1; … … 248 259 printf("mount.cifs failed: password in credentials file too long\n"); 249 260 memset(line_buf,0, 4096); 250 exit( 1);261 exit(EX_USAGE); 251 262 } else { 252 263 if(mountpassword == NULL) { … … 276 287 if(length > DOMAIN_SIZE) { 277 288 printf("mount.cifs failed: domain in credentials file too long\n"); 278 exit( 1);289 exit(EX_USAGE); 279 290 } else { 280 291 if(domain_name == NULL) { … … 309 320 if (mountpassword == NULL) { 310 321 printf("malloc failed\n"); 311 exit( 1);322 exit(EX_SYSERR); 312 323 } 313 324 … … 317 328 printf("mount.cifs failed. %s attempting to open password file %s\n", 318 329 strerror(errno),filename); 319 exit( 1);330 exit(EX_SYSERR); 320 331 } 321 332 } … … 328 339 if(filename != NULL) 329 340 close(file_descript); 330 exit( 1);341 exit(EX_SYSERR); 331 342 } else if(rc == 0) { 332 343 if(mountpassword[0] == 0) { … … 423 434 } else { 424 435 printf("username specified with no parameter\n"); 436 SAFE_FREE(out); 425 437 return 1; /* needs_arg; */ 426 438 } … … 455 467 } else { 456 468 printf("username too long\n"); 469 SAFE_FREE(out); 457 470 return 1; 458 471 } … … 470 483 } else { 471 484 printf("password too long\n"); 485 SAFE_FREE(out); 472 486 return 1; 473 487 } … … 486 500 } else { 487 501 printf("ip address too long\n"); 502 SAFE_FREE(out); 488 503 return 1; 489 504 } … … 493 508 if (!value || !*value) { 494 509 printf("invalid path to network resource\n"); 510 SAFE_FREE(out); 495 511 return 1; /* needs_arg; */ 496 512 } else if(strnlen(value,5) < 5) { … … 507 523 } else if (strncmp(value, "\\\\", 2) != 0) { 508 524 printf("UNC Path does not begin with // or \\\\ \n"); 525 SAFE_FREE(out); 509 526 return 1; 510 527 } else { … … 516 533 } else { 517 534 printf("CIFS: UNC name too long\n"); 535 SAFE_FREE(out); 518 536 return 1; 519 537 } … … 522 540 if (!value || !*value) { 523 541 printf("CIFS: invalid domain name\n"); 542 SAFE_FREE(out); 524 543 return 1; /* needs_arg; */ 525 544 } … … 528 547 } else { 529 548 printf("domain name too long\n"); 549 SAFE_FREE(out); 530 550 return 1; 531 551 } … … 536 556 printf("error %d (%s) opening credential file %s\n", 537 557 rc, strerror(rc), value); 558 SAFE_FREE(out); 538 559 return 1; 539 560 } 540 561 } else { 541 562 printf("invalid credential file name specified\n"); 563 SAFE_FREE(out); 542 564 return 1; 543 565 } … … 550 572 if (!(pw = getpwnam(value))) { 551 573 printf("bad user name \"%s\"\n", value); 552 exit( 1);574 exit(EX_USAGE); 553 575 } 554 576 snprintf(user, sizeof(user), "%u", pw->pw_uid); … … 566 588 if (!(gr = getgrnam(value))) { 567 589 printf("bad group name \"%s\"\n", value); 568 exit( 1);590 exit(EX_USAGE); 569 591 } 570 592 snprintf(group, sizeof(group), "%u", gr->gr_gid); … … 578 600 if (!value || !*value) { 579 601 printf ("Option '%s' requires a numerical argument\n", data); 602 SAFE_FREE(out); 580 603 return 1; 581 604 } … … 592 615 if (!value || !*value) { 593 616 printf ("Option '%s' requires a numerical argument\n", data); 617 SAFE_FREE(out); 594 618 return 1; 595 619 } … … 661 685 if (out == NULL) { 662 686 perror("malloc"); 663 exit( 1);687 exit(EX_SYSERR); 664 688 } 665 689 … … 686 710 if (out == NULL) { 687 711 perror("malloc"); 688 exit( 1);712 exit(EX_SYSERR); 689 713 } 690 714 … … 702 726 if (out == NULL) { 703 727 perror("malloc"); 704 exit( 1);728 exit(EX_SYSERR); 705 729 } 706 730 … … 983 1007 984 1008 /* convert a string to uppercase. return false if the string 985 * wasn't ASCII or wasa NULL ptr */1009 * wasn't ASCII. Return success on a NULL ptr */ 986 1010 static int 987 1011 uppercase_string(char *string) 988 1012 { 989 1013 if (!string) 990 return 0;1014 return 1; 991 1015 992 1016 while (*string) { … … 1037 1061 } else { 1038 1062 mount_cifs_usage(); 1039 exit( 1);1063 exit(EX_USAGE); 1040 1064 } 1041 1065 … … 1054 1078 if (share_name == NULL) { 1055 1079 fprintf(stderr, "%s: %s", argv[0], strerror(ENOMEM)); 1056 exit( 1);1080 exit(EX_SYSERR); 1057 1081 } 1058 1082 mountpoint = argv[2]; 1059 1083 } else { 1060 1084 mount_cifs_usage(); 1061 exit( 1);1085 exit(EX_USAGE); 1062 1086 } 1063 1087 … … 1081 1105 case 'h': /* help */ 1082 1106 mount_cifs_usage (); 1083 exit( 1);1107 exit(EX_USAGE); 1084 1108 case 'n': 1085 1109 ++nomtab; … … 1135 1159 if (*ep) { 1136 1160 printf("bad uid value \"%s\"\n", optarg); 1137 exit( 1);1161 exit(EX_USAGE); 1138 1162 } 1139 1163 } else { … … 1142 1166 if (!(pw = getpwnam(optarg))) { 1143 1167 printf("bad user name \"%s\"\n", optarg); 1144 exit( 1);1168 exit(EX_USAGE); 1145 1169 } 1146 1170 uid = pw->pw_uid; … … 1155 1179 if (*ep) { 1156 1180 printf("bad gid value \"%s\"\n", optarg); 1157 exit( 1);1181 exit(EX_USAGE); 1158 1182 } 1159 1183 } else { … … 1162 1186 if (!(gr = getgrnam(optarg))) { 1163 1187 printf("bad user name \"%s\"\n", optarg); 1164 exit( 1);1188 exit(EX_USAGE); 1165 1189 } 1166 1190 gid = gr->gr_gid; … … 1192 1216 printf("unknown mount option %c\n",c); 1193 1217 mount_cifs_usage(); 1194 exit( 1);1218 exit(EX_USAGE); 1195 1219 } 1196 1220 } … … 1198 1222 if((argc < 3) || (dev_name == NULL) || (mountpoint == NULL)) { 1199 1223 mount_cifs_usage(); 1200 exit( 1);1224 exit(EX_USAGE); 1201 1225 } 1202 1226 … … 1215 1239 1216 1240 if (orgoptions && parse_options(&orgoptions, &flags)) { 1217 rc = -1;1241 rc = EX_USAGE; 1218 1242 goto mount_exit; 1219 1243 } … … 1221 1245 if((ipaddr == NULL) && (got_ip == 0)) { 1222 1246 printf("No ip address specified and hostname not found\n"); 1223 rc = -1;1247 rc = EX_USAGE; 1224 1248 goto mount_exit; 1225 1249 } … … 1236 1260 if(chdir(mountpoint)) { 1237 1261 printf("mount error: can not change directory into mount target %s\n",mountpoint); 1238 rc = -1;1262 rc = EX_USAGE; 1239 1263 goto mount_exit; 1240 1264 } … … 1242 1266 if(stat (".", &statbuf)) { 1243 1267 printf("mount error: mount point %s does not exist\n",mountpoint); 1244 rc = -1;1268 rc = EX_USAGE; 1245 1269 goto mount_exit; 1246 1270 } … … 1248 1272 if (S_ISDIR(statbuf.st_mode) == 0) { 1249 1273 printf("mount error: mount point %s is not a directory\n",mountpoint); 1250 rc = -1;1274 rc = EX_USAGE; 1251 1275 goto mount_exit; 1252 1276 } … … 1261 1285 } else { 1262 1286 printf("mount error: permission denied or not superuser and mount.cifs not installed SUID\n"); 1263 return -1;1287 exit(EX_USAGE); 1264 1288 } 1265 1289 } … … 1276 1300 if (!tmp_pass || !mountpassword) { 1277 1301 printf("Password not entered, exiting\n"); 1278 return -1;1302 exit(EX_USAGE); 1279 1303 } 1280 1304 strlcpy(mountpassword, tmp_pass, MOUNT_PASSWD_SIZE+1); … … 1294 1318 printf("No server share name specified\n"); 1295 1319 printf("\nMounting the DFS root for server not implemented yet\n"); 1296 exit( 1);1320 exit(EX_USAGE); 1297 1321 } 1298 1322 if(user_name) … … 1308 1332 if(options == NULL) { 1309 1333 printf("Could not allocate memory for mount options\n"); 1310 return -1;1334 exit(EX_SYSERR); 1311 1335 } 1312 1336 … … 1387 1411 } 1388 1412 printf("Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n"); 1389 rc = -1; 1390 goto mount_exit; 1413 rc = EX_FAIL; 1391 1414 } else { 1415 atexit(unlock_mtab); 1416 rc = lock_mtab(); 1417 if (rc) { 1418 printf("cannot lock mtab"); 1419 goto mount_exit; 1420 } 1392 1421 pmntfile = setmntent(MOUNTED, "a+"); 1393 if(pmntfile) { 1394 mountent.mnt_fsname = dev_name; 1395 mountent.mnt_dir = mountpoint; 1396 mountent.mnt_type = CONST_DISCARD(char *,"cifs"); 1397 mountent.mnt_opts = (char *)malloc(220); 1398 if(mountent.mnt_opts) { 1399 char * mount_user = getusername(); 1400 memset(mountent.mnt_opts,0,200); 1401 if(flags & MS_RDONLY) 1402 strlcat(mountent.mnt_opts,"ro",220); 1403 else 1404 strlcat(mountent.mnt_opts,"rw",220); 1405 if(flags & MS_MANDLOCK) 1406 strlcat(mountent.mnt_opts,",mand",220); 1407 if(flags & MS_NOEXEC) 1408 strlcat(mountent.mnt_opts,",noexec",220); 1409 if(flags & MS_NOSUID) 1410 strlcat(mountent.mnt_opts,",nosuid",220); 1411 if(flags & MS_NODEV) 1412 strlcat(mountent.mnt_opts,",nodev",220); 1413 if(flags & MS_SYNCHRONOUS) 1414 strlcat(mountent.mnt_opts,",synch",220); 1415 if(mount_user) { 1416 if(getuid() != 0) { 1417 strlcat(mountent.mnt_opts,",user=",220); 1418 strlcat(mountent.mnt_opts,mount_user,220); 1419 } 1420 /* free(mount_user); do not free static mem */ 1421 } 1422 } 1423 mountent.mnt_freq = 0; 1424 mountent.mnt_passno = 0; 1425 rc = addmntent(pmntfile,&mountent); 1426 endmntent(pmntfile); 1427 SAFE_FREE(mountent.mnt_opts); 1428 } else { 1429 printf("could not update mount table\n"); 1430 } 1431 } 1432 rc = 0; 1422 if (!pmntfile) { 1423 printf("could not update mount table\n"); 1424 unlock_mtab(); 1425 rc = EX_FILEIO; 1426 goto mount_exit; 1427 } 1428 mountent.mnt_fsname = dev_name; 1429 mountent.mnt_dir = mountpoint; 1430 mountent.mnt_type = CONST_DISCARD(char *,"cifs"); 1431 mountent.mnt_opts = (char *)malloc(220); 1432 if(mountent.mnt_opts) { 1433 char * mount_user = getusername(); 1434 memset(mountent.mnt_opts,0,200); 1435 if(flags & MS_RDONLY) 1436 strlcat(mountent.mnt_opts,"ro",220); 1437 else 1438 strlcat(mountent.mnt_opts,"rw",220); 1439 if(flags & MS_MANDLOCK) 1440 strlcat(mountent.mnt_opts,",mand",220); 1441 if(flags & MS_NOEXEC) 1442 strlcat(mountent.mnt_opts,",noexec",220); 1443 if(flags & MS_NOSUID) 1444 strlcat(mountent.mnt_opts,",nosuid",220); 1445 if(flags & MS_NODEV) 1446 strlcat(mountent.mnt_opts,",nodev",220); 1447 if(flags & MS_SYNCHRONOUS) 1448 strlcat(mountent.mnt_opts,",sync",220); 1449 if(mount_user) { 1450 if(getuid() != 0) { 1451 strlcat(mountent.mnt_opts, 1452 ",user=", 220); 1453 strlcat(mountent.mnt_opts, 1454 mount_user, 220); 1455 } 1456 } 1457 } 1458 mountent.mnt_freq = 0; 1459 mountent.mnt_passno = 0; 1460 rc = addmntent(pmntfile,&mountent); 1461 endmntent(pmntfile); 1462 unlock_mtab(); 1463 SAFE_FREE(mountent.mnt_opts); 1464 if (rc) 1465 rc = EX_FILEIO; 1466 } 1433 1467 mount_exit: 1434 1468 if(mountpassword) { … … 1442 1476 SAFE_FREE(resolved_path); 1443 1477 SAFE_FREE(share_name); 1444 return rc;1478 exit(rc); 1445 1479 }
Note:
See TracChangeset
for help on using the changeset viewer.