summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve French <sfrench@samba.org>2007-05-17 22:28:28 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:22:13 -0500
commit58703289a32ff0311226f12540cf56eeca0cc0a0 (patch)
tree8ec787dee9843d37a920ac4f5c6c7a343c2fa8cb
parent0e9210d0eaf0c9de231e48e671cfb0861d62a1da (diff)
downloadsamba-58703289a32ff0311226f12540cf56eeca0cc0a0.tar.gz
samba-58703289a32ff0311226f12540cf56eeca0cc0a0.tar.bz2
samba-58703289a32ff0311226f12540cf56eeca0cc0a0.zip
r22979: Revert previous checkin (which had some debug junk) and fix misc frees that
valgrind noticed (This used to be commit c8aa60692ba23c43820b820db3371a86dfbf40b5)
-rwxr-xr-xsource3/client/mount.cifs.c93
1 files changed, 25 insertions, 68 deletions
diff --git a/source3/client/mount.cifs.c b/source3/client/mount.cifs.c
index cfcdaf9974..77074644e0 100755
--- a/source3/client/mount.cifs.c
+++ b/source3/client/mount.cifs.c
@@ -79,7 +79,7 @@ static char * user_name = NULL;
static char * mountpassword = NULL;
char * domain_name = NULL;
char * prefixpath = NULL;
-char * servern = NULL;
+
/* BB finish BB
@@ -128,8 +128,7 @@ static char * getusername(void) {
struct passwd *password = getpwuid(getuid());
if (password) {
- if(password->pw_name);
- username = strdup(password->pw_name);
+ username = password->pw_name;
}
return username;
}
@@ -420,11 +419,6 @@ static int parse_options(char ** optionsp, int * filesys_flags)
printf("password too long\n");
return 1;
}
- } else if (strncmp(data, "sec", 3) == 0) {
- if (value) {
- if (!strcmp(value, "none"))
- got_password = 1;
- }
} else if (strncmp(data, "ip", 2) == 0) {
if (!value || !*value) {
printf("target ip address argument missing");
@@ -573,6 +567,8 @@ static int parse_options(char ** optionsp, int * filesys_flags)
*filesys_flags &= ~MS_NOEXEC;
} else if (strncmp(data, "guest", 5) == 0) {
got_password=1;
+ /* remove the parm since it would otherwise be logged by kern */
+ goto nocopy;
} else if (strncmp(data, "ro", 2) == 0) {
*filesys_flags |= MS_RDONLY;
} else if (strncmp(data, "rw", 2) == 0) {
@@ -809,9 +805,6 @@ continue_unc_parsing:
if(got_ip == 0) {
host_entry = gethostbyname(unc_name);
}
- if(strnlen(unc_name, 16) < 16) {
- servern = strdup(unc_name);
- }
*(share - 1) = '/'; /* put the slash back */
if ((prefixpath = strchr(share, '/'))) {
*prefixpath = 0; /* permanently terminate the string */
@@ -888,7 +881,7 @@ int main(int argc, char ** argv)
char * uuid = NULL;
char * mountpoint = NULL;
char * options = NULL;
- char * resolved_path;
+ char * resolved_path = NULL;
char * temp;
int rc;
int rsize = 0;
@@ -899,7 +892,6 @@ int main(int argc, char ** argv)
int optlen = 0;
int orgoptlen = 0;
int retry = 0; /* set when we have to retry mount with uppercase */
- int retry_with_rfc1001name = 0; /* set when we have to retry with netbios name */
struct stat statbuf;
struct utsname sysinfo;
struct mntent mountent;
@@ -1085,12 +1077,15 @@ int main(int argc, char ** argv)
get_password_from_file(0, getenv("PASSWD_FILE"));
}
- if (orgoptions && parse_options(&orgoptions, &flags))
- return -1;
+ if (orgoptions && parse_options(&orgoptions, &flags)) {
+ rc = -1;
+ goto mount_exit;
+ }
ipaddr = parse_server(&share_name);
if((ipaddr == NULL) && (got_ip == 0)) {
printf("No ip address specified and hostname not found\n");
- return -1;
+ rc = -1;
+ goto mount_exit;
}
/* BB save off path and pop after mount returns? */
@@ -1104,17 +1099,20 @@ int main(int argc, char ** argv)
}
if(chdir(mountpoint)) {
printf("mount error: can not change directory into mount target %s\n",mountpoint);
- return -1;
+ rc = -1;
+ goto mount_exit;
}
if(stat (".", &statbuf)) {
printf("mount error: mount point %s does not exist\n",mountpoint);
- return -1;
+ rc = -1;
+ goto mount_exit;
}
if (S_ISDIR(statbuf.st_mode) == 0) {
printf("mount error: mount point %s is not a directory\n",mountpoint);
- return -1;
+ rc = -1;
+ goto mount_exit;
}
if((getuid() != 0) && (geteuid() == 0)) {
@@ -1160,40 +1158,28 @@ mount_retry:
optlen += strlen(ipaddr) + 4;
if(mountpassword)
optlen += strlen(mountpassword) + 6;
- if(options) {
- printf("\norg options %s at %p\n", options, options); /* BB removeme BB */
-
+ if(options)
free(options);
- }
- options = 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 */) + 9 /* servern=" */ + 16 /* space for maximum RFC1001 name */;
+ 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 */);
+
if(options == NULL) {
printf("Could not allocate memory for mount options\n");
return -1;
}
+
- printf("\noptions %s at %p\n", options, options); /* BB removeme BB */
- options = realloc(options, 3350); /* BB removeme BB */
- printf("\nrealloc seems ok\n"); /* BB removeme BB */
options[0] = 0;
strncat(options,"unc=",4);
strcat(options,share_name);
/* scan backwards and reverse direction of slash */
temp = strrchr(options, '/');
- options = realloc(options, 980); /* BB removeme BB */
- printf("\nrealloc seemms very ok\n"); /* BB removeme BB */
if(temp > options + 6)
*temp = '\\';
if(ipaddr) {
strncat(options,",ip=",4);
strcat(options,ipaddr);
}
- if((servern) && retry_with_rfc1001name) {
- strcat(options, ",servern=");
- strcat(options, servern);
- }
- printf("\noptions1 %s at %p\n", options, options); /* BB removeme BB */
- options = realloc(options, 1000); /* BB removeme BB */
- printf("realloc1 ok\n"); /* BB removeme BB */
+
if(user_name) {
/* check for syntax like user=domain\user */
if(got_domain == 0)
@@ -1217,7 +1203,6 @@ mount_retry:
strncat(options,",pass=",6);
strcat(options,mountpassword);
}
- printf("\noptions2 %s at %p\n", options, options); /* BB removeme BB */
strncat(options,",ver=",5);
strcat(options,MOUNT_CIFS_VERSION_MAJOR);
@@ -1226,9 +1211,6 @@ mount_retry:
strcat(options,",");
strcat(options,orgoptions);
}
-
- printf("\noptions2 at %p\n", options); /* BB removeme BB */
-
if(prefixpath) {
strncat(options,",prefixpath=",12);
strcat(options,prefixpath); /* no need to cat the / */
@@ -1246,22 +1228,6 @@ mount_retry:
case ENODEV:
printf("mount error: cifs filesystem not supported by the system\n");
break;
- case ENOENT:
- case EHOSTDOWN:
- /* If this is so old as to not support *SMBSERVER called
- name for RFC1001, we can get this error . We also
- need to uppercase the sharename for these old servers
- so fall through to retry code below. On retry the
- code will add "servern=" */
- tmp = servern;
- if((retry == 0) && tmp) {
- retry_with_rfc1001name = 1;
- while (*tmp && !(((unsigned char)tmp[0]) & 0x80)) {
- *tmp = toupper((unsigned char)*tmp);
- tmp++;
- }
- printf("Adding Netbios name of server to mount based on server part of UNC name\n");
- }
case ENXIO:
if(retry == 0) {
retry = 1;
@@ -1310,7 +1276,7 @@ mount_retry:
strcat(mountent.mnt_opts,",user=");
strcat(mountent.mnt_opts,mount_user);
}
- free(mount_user);
+ /* free(mount_user); do not free static mem */
}
}
mountent.mnt_freq = 0;
@@ -1332,9 +1298,7 @@ mount_exit:
}
if(options) {
- options = realloc(options, 1000); /* BB removeme BB */
- printf("\noptions freed %p\n", options); /* BB removeme BB */
-/* memset(options,0,optlen); */
+ memset(options,0,optlen);
free(options);
}
@@ -1345,17 +1309,10 @@ mount_exit:
if(resolved_path) {
free(resolved_path);
}
-
- if(servern) {
- free(servern);
- }
if(free_share_name) {
free(share_name);
- }
- if(user_name)
- free(user_name);
-
+ }
return rc;
}