Changeset 429 for trunk/server/client/mount.cifs.c
- Timestamp:
- Apr 9, 2010, 3:51:41 PM (15 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
-
Property svn:mergeinfo
set to
/vendor/3.5.2 merged eligible /vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
trunk/server/client/mount.cifs.c
r414 r429 44 44 45 45 #define MOUNT_CIFS_VERSION_MAJOR "1" 46 #define MOUNT_CIFS_VERSION_MINOR "1 3"46 #define MOUNT_CIFS_VERSION_MINOR "14" 47 47 48 48 #ifndef MOUNT_CIFS_VENDOR_SUFFIX … … 88 88 /* currently maximum length of IPv6 address string */ 89 89 #define MAX_ADDRESS_LEN INET6_ADDRSTRLEN 90 91 /* 92 * mount.cifs has been the subject of many "security" bugs that have arisen 93 * because of users and distributions installing it as a setuid root program. 94 * mount.cifs has not been audited for security. Thus, we strongly recommend 95 * that it not be installed setuid root. To make that abundantly clear, 96 * mount.cifs now check whether it's running setuid root and exit with an 97 * error if it is. If you wish to disable this check, then set the following 98 * #define to 1, but please realize that you do so at your own peril. 99 */ 100 #define CIFS_DISABLE_SETUID_CHECK 0 90 101 91 102 /* … … 180 191 181 192 /* does mountpoint exist and is it a directory? */ 182 err = stat( mountpoint, &statbuf);193 err = stat(".", &statbuf); 183 194 if (err) { 184 195 fprintf(stderr, "%s: failed to stat %s: %s\n", progname, … … 213 224 return 0; 214 225 } 226 227 #if CIFS_DISABLE_SETUID_CHECK 228 static int 229 check_setuid(void) 230 { 231 return 0; 232 } 233 #else /* CIFS_DISABLE_SETUID_CHECK */ 234 static int 235 check_setuid(void) 236 { 237 if (getuid() && !geteuid()) { 238 printf("This mount.cifs program has been built with the " 239 "ability to run as a setuid root program disabled.\n" 240 "mount.cifs has not been well audited for security " 241 "holes. Therefore the Samba team does not recommend " 242 "installing it as a setuid root program.\n"); 243 return 1; 244 } 245 246 return 0; 247 } 248 #endif /* CIFS_DISABLE_SETUID_CHECK */ 215 249 216 250 #if CIFS_LEGACY_SETUID_CHECK … … 1166 1200 } 1167 1201 1202 /* 1203 * This function borrowed from fuse-utils... 1204 * 1205 * glibc's addmntent (at least as of 2.10 or so) doesn't properly encode 1206 * newlines embedded within the text fields. To make sure no one corrupts 1207 * the mtab, fail the mount if there are embedded newlines. 1208 */ 1209 static int check_newline(const char *progname, const char *name) 1210 { 1211 char *s; 1212 for (s = "\n"; *s; s++) { 1213 if (strchr(name, *s)) { 1214 fprintf(stderr, "%s: illegal character 0x%02x in mount entry\n", 1215 progname, *s); 1216 return EX_USAGE; 1217 } 1218 } 1219 return 0; 1220 } 1221 1222 static int check_mtab(const char *progname, const char *devname, 1223 const char *dir) 1224 { 1225 if (check_newline(progname, devname) == -1 || 1226 check_newline(progname, dir) == -1) 1227 return EX_USAGE; 1228 return 0; 1229 } 1230 1231 1168 1232 int main(int argc, char ** argv) 1169 1233 { … … 1198 1262 FILE * pmntfile; 1199 1263 1264 if (check_setuid()) 1265 return EX_USAGE; 1266 1200 1267 /* setlocale(LC_ALL, ""); 1201 1268 bindtextdomain(PACKAGE, LOCALEDIR); … … 1379 1446 1380 1447 /* make sure mountpoint is legit */ 1448 rc = chdir(mountpoint); 1449 if (rc) { 1450 fprintf(stderr, "Couldn't chdir to %s: %s\n", mountpoint, 1451 strerror(errno)); 1452 rc = EX_USAGE; 1453 goto mount_exit; 1454 } 1455 1381 1456 rc = check_mountpoint(thisprogram, mountpoint); 1382 1457 if (rc) … … 1441 1516 /* BB save off path and pop after mount returns? */ 1442 1517 resolved_path = (char *)malloc(PATH_MAX+1); 1443 if(resolved_path) { 1444 /* Note that if we can not canonicalize the name, we get 1445 another chance to see if it is valid when we chdir to it */ 1446 if (realpath(mountpoint, resolved_path)) { 1447 mountpoint = resolved_path; 1448 } 1449 } 1518 if (!resolved_path) { 1519 fprintf(stderr, "Unable to allocate memory.\n"); 1520 rc = EX_SYSERR; 1521 goto mount_exit; 1522 } 1523 1524 /* Note that if we can not canonicalize the name, we get 1525 another chance to see if it is valid when we chdir to it */ 1526 if(!realpath(".", resolved_path)) { 1527 fprintf(stderr, "Unable to resolve %s to canonical path: %s\n", 1528 mountpoint, strerror(errno)); 1529 rc = EX_SYSERR; 1530 goto mount_exit; 1531 } 1532 1533 mountpoint = resolved_path; 1534 1450 1535 if(got_user == 0) { 1451 1536 /* Note that the password will not be retrieved from the … … 1591 1676 fprintf(stderr, "\n"); 1592 1677 1593 if (!fakemnt && mount(dev_name, mountpoint, "cifs", flags, options)) { 1678 rc = check_mtab(thisprogram, dev_name, mountpoint); 1679 if (rc) 1680 goto mount_exit; 1681 1682 if (!fakemnt && mount(dev_name, ".", "cifs", flags, options)) { 1594 1683 switch (errno) { 1595 1684 case ECONNREFUSED:
Note:
See TracChangeset
for help on using the changeset viewer.