This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
static char * mountpassword = NULL;
char * domain_name = NULL;
char * prefixpath = NULL;
-char * servern = NULL;
+
/* BB finish BB
struct passwd *password = getpwuid(getuid());
if (password) {
- if(password->pw_name);
- username = strdup(password->pw_name);
+ username = password->pw_name;
}
return username;
}
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 */
char * uuid = NULL;
char * mountpoint = NULL;
char * options = NULL;
- char * resolved_path;
+ char * resolved_path = NULL;
char * temp;
int rc;
int rsize = 0;
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;
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? */
}
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)) {
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)
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);
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 / */
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;
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;
}
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);
}
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;
}