diff options
Diffstat (limited to 'source/client/smbmount.c')
-rw-r--r-- | source/client/smbmount.c | 134 |
1 files changed, 60 insertions, 74 deletions
diff --git a/source/client/smbmount.c b/source/client/smbmount.c index 0db990e8bd6..40e21e1eb1d 100644 --- a/source/client/smbmount.c +++ b/source/client/smbmount.c @@ -1,5 +1,6 @@ /* - Unix SMB/CIFS implementation. + Unix SMB/Netbios implementation. + Version 2.0. SMBFS mount program Copyright (C) Andrew Tridgell 1999 @@ -29,6 +30,7 @@ extern BOOL in_client; extern pstring user_socket_options; extern BOOL append_log; +extern fstring remote_machine; static pstring credentials; static pstring my_netbios_name; @@ -41,7 +43,7 @@ static pstring options; static struct in_addr dest_ip; static BOOL have_ip; -static int smb_port = 0; +static int smb_port = 139; static BOOL got_pass; static uid_t mount_uid; static gid_t mount_gid; @@ -109,7 +111,8 @@ static void usr1_handler(int x) /***************************************************** return a connection to a server *******************************************************/ -static struct cli_state *do_connection(char *the_service) + +static struct cli_state *do_connection(char *svc_name) { struct cli_state *c; struct nmb_name called, calling; @@ -118,13 +121,13 @@ static struct cli_state *do_connection(char *the_service) pstring server; char *share; - if (the_service[0] != '\\' || the_service[1] != '\\') { + if (svc_name[0] != '\\' || svc_name[1] != '\\') { usage(); exit(1); } - pstrcpy(server, the_service+2); - share = strchr_m(server,'\\'); + pstrcpy(server, svc_name+2); + share = strchr(server,'\\'); if (!share) { usage(); exit(1); @@ -138,28 +141,25 @@ static struct cli_state *do_connection(char *the_service) make_nmb_name(&called , server, 0x20); again: - zero_ip(&ip); + zero_ip(&ip); if (have_ip) ip = dest_ip; /* have to open a new connection */ - if (!(c=cli_initialise(NULL)) || (cli_set_port(c, smb_port) != smb_port) || + if (!(c=cli_initialise(NULL)) || (cli_set_port(c, smb_port) == 0) || !cli_connect(c, server_n, &ip)) { - DEBUG(0,("%d: Connection to %s failed\n", sys_getpid(), server_n)); + DEBUG(0,("%d: Connection to %s failed\n", getpid(), server_n)); if (c) { cli_shutdown(c); } return NULL; } - /* SPNEGO doesn't work till we get NTSTATUS error support */ - c->use_spnego = False; - if (!cli_session_request(c, &calling, &called)) { char *p; DEBUG(0,("%d: session request to %s failed (%s)\n", - sys_getpid(), called.name, cli_errstr(c))); + getpid(), called.name, cli_errstr(c))); cli_shutdown(c); - if ((p=strchr_m(called.name, '.'))) { + if ((p=strchr(called.name, '.'))) { *p = 0; goto again; } @@ -170,10 +170,10 @@ static struct cli_state *do_connection(char *the_service) return NULL; } - DEBUG(4,("%d: session request ok\n", sys_getpid())); + DEBUG(4,("%d: session request ok\n", getpid())); if (!cli_negprot(c)) { - DEBUG(0,("%d: protocol negotiation failed\n", sys_getpid())); + DEBUG(0,("%d: protocol negotiation failed\n", getpid())); cli_shutdown(c); return NULL; } @@ -186,37 +186,37 @@ static struct cli_state *do_connection(char *the_service) } /* This should be right for current smbfs. Future versions will support - large files as well as unicode and oplocks. */ + large files as well as unicode and oplocks. */ c->capabilities &= ~(CAP_UNICODE | CAP_LARGE_FILES | CAP_NT_SMBS | - CAP_NT_FIND | CAP_STATUS32 | CAP_LEVEL_II_OPLOCKS); + CAP_NT_FIND | CAP_STATUS32 | CAP_LEVEL_II_OPLOCKS); c->force_dos_errors = True; if (!cli_session_setup(c, username, password, strlen(password), password, strlen(password), workgroup)) { /* if a password was not supplied then try again with a - null username */ + null username */ if (password[0] || !username[0] || - !cli_session_setup(c, "", "", 0, "", 0, workgroup)) { + !cli_session_setup(c, "", "", 0, "", 0, workgroup)) { DEBUG(0,("%d: session setup failed: %s\n", - sys_getpid(), cli_errstr(c))); + getpid(), cli_errstr(c))); cli_shutdown(c); return NULL; } DEBUG(0,("Anonymous login successful\n")); } - DEBUG(4,("%d: session setup ok\n", sys_getpid())); + DEBUG(4,("%d: session setup ok\n", getpid())); if (!cli_send_tconX(c, share, "?????", password, strlen(password)+1)) { DEBUG(0,("%d: tree connect failed: %s\n", - sys_getpid(), cli_errstr(c))); + getpid(), cli_errstr(c))); cli_shutdown(c); return NULL; } - DEBUG(4,("%d: tconx ok\n", sys_getpid())); + DEBUG(4,("%d: tconx ok\n", getpid())); got_pass = True; @@ -246,12 +246,12 @@ static void smb_umount(char *mount_point) */ if (umount(mount_point) != 0) { DEBUG(0,("%d: Could not umount %s: %s\n", - sys_getpid(), mount_point, strerror(errno))); + getpid(), mount_point, strerror(errno))); return; } if ((fd = open(MOUNTED"~", O_RDWR|O_CREAT|O_EXCL, 0600)) == -1) { - DEBUG(0,("%d: Can't get "MOUNTED"~ lock file", sys_getpid())); + DEBUG(0,("%d: Can't get "MOUNTED"~ lock file", getpid())); return; } @@ -259,7 +259,7 @@ static void smb_umount(char *mount_point) if ((mtab = setmntent(MOUNTED, "r")) == NULL) { DEBUG(0,("%d: Can't open " MOUNTED ": %s\n", - sys_getpid(), strerror(errno))); + getpid(), strerror(errno))); return; } @@ -267,7 +267,7 @@ static void smb_umount(char *mount_point) if ((new_mtab = setmntent(MOUNTED_TMP, "w")) == NULL) { DEBUG(0,("%d: Can't open " MOUNTED_TMP ": %s\n", - sys_getpid(), strerror(errno))); + getpid(), strerror(errno))); endmntent(mtab); return; } @@ -282,7 +282,7 @@ static void smb_umount(char *mount_point) if (fchmod (fileno (new_mtab), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) { DEBUG(0,("%d: Error changing mode of %s: %s\n", - sys_getpid(), MOUNTED_TMP, strerror(errno))); + getpid(), MOUNTED_TMP, strerror(errno))); return; } @@ -290,12 +290,12 @@ static void smb_umount(char *mount_point) if (rename(MOUNTED_TMP, MOUNTED) < 0) { DEBUG(0,("%d: Cannot rename %s to %s: %s\n", - sys_getpid(), MOUNTED, MOUNTED_TMP, strerror(errno))); + getpid(), MOUNTED, MOUNTED_TMP, strerror(errno))); return; } if (unlink(MOUNTED"~") == -1) { - DEBUG(0,("%d: Can't remove "MOUNTED"~", sys_getpid())); + DEBUG(0,("%d: Can't remove "MOUNTED"~", getpid())); return; } } @@ -307,7 +307,7 @@ static void smb_umount(char *mount_point) * not exit after open_sockets() or send_login() errors, * as the smbfs mount would then have no way to recover. */ -static void send_fs_socket(char *the_service, char *mount_point, struct cli_state *c) +static void send_fs_socket(char *svc_name, char *mount_point, struct cli_state *c) { int fd, closed = 0, res = 1; pid_t parentpid = getppid(); @@ -318,7 +318,7 @@ static void send_fs_socket(char *the_service, char *mount_point, struct cli_stat while (1) { if ((fd = open(mount_point, O_RDONLY)) < 0) { DEBUG(0,("mount.smbfs[%d]: can't open %s\n", - sys_getpid(), mount_point)); + getpid(), mount_point)); break; } @@ -338,7 +338,7 @@ static void send_fs_socket(char *the_service, char *mount_point, struct cli_stat res = ioctl(fd, SMB_IOC_NEWCONN, &conn_options); if (res != 0) { DEBUG(0,("mount.smbfs[%d]: ioctl failed, res=%d\n", - sys_getpid(), res)); + getpid(), res)); close(fd); break; } @@ -376,11 +376,11 @@ static void send_fs_socket(char *the_service, char *mount_point, struct cli_stat } /* here we are no longer interactive */ - set_remote_machine_name("smbmount"); /* sneaky ... */ + pstrcpy(remote_machine, "smbmount"); /* sneaky ... */ setup_logging("mount.smbfs", False); append_log = True; reopen_logs(); - DEBUG(0, ("mount.smbfs: entering daemon mode for service %s, pid=%d\n", the_service, sys_getpid())); + DEBUG(0, ("mount.smbfs: entering daemon mode for service %s, pid=%d\n", svc_name, getpid())); closed = 1; } @@ -390,20 +390,20 @@ static void send_fs_socket(char *the_service, char *mount_point, struct cli_stat while (!c) { CatchSignal(SIGUSR1, &usr1_handler); pause(); - DEBUG(2,("mount.smbfs[%d]: got signal, getting new socket\n", sys_getpid())); - c = do_connection(the_service); + DEBUG(2,("mount.smbfs[%d]: got signal, getting new socket\n", getpid())); + c = do_connection(svc_name); } } smb_umount(mount_point); - DEBUG(2,("mount.smbfs[%d]: exit\n", sys_getpid())); + DEBUG(2,("mount.smbfs[%d]: exit\n", getpid())); exit(1); } -/** - * Mount a smbfs - **/ +/**************************************************************************** +mount smbfs +****************************************************************************/ static void init_mount(void) { char mount_point[MAXPATHLEN+1]; @@ -473,22 +473,13 @@ static void init_mount(void) } if (sys_fork() == 0) { - char *smbmnt_path; - - asprintf(&smbmnt_path, "%s/smbmnt", dyn_BINDIR); - - if (file_exist(smbmnt_path, NULL)) { - execv(smbmnt_path, args); - fprintf(stderr, - "smbfs/init_mount: execv of %s failed. Error was %s.", - smbmnt_path, strerror(errno)); + if (file_exist(BINDIR "/smbmnt", NULL)) { + execv(BINDIR "/smbmnt", args); + fprintf(stderr,"execv of %s failed. Error was %s.", BINDIR "/smbmnt", strerror(errno)); } else { execvp("smbmnt", args); - fprintf(stderr, - "smbfs/init_mount: execv of %s failed. Error was %s.", - "smbmnt", strerror(errno)); + fprintf(stderr,"execvp of smbmnt failed. Error was %s.", strerror(errno) ); } - free(smbmnt_path); exit(1); } @@ -713,7 +704,7 @@ static void parse_mount_smb(int argc, char **argv) */ for (opts = strtok(optarg, ","); opts; opts = strtok(NULL, ",")) { DEBUG(3, ("opts: %s\n", opts)); - if ((opteq = strchr_m(opts, '='))) { + if ((opteq = strchr(opts, '='))) { val = atoi(opteq + 1); *opteq = '\0'; @@ -721,13 +712,13 @@ static void parse_mount_smb(int argc, char **argv) !strcmp(opts, "logon")) { char *lp; pstrcpy(username,opteq+1); - if ((lp=strchr_m(username,'%'))) { + if ((lp=strchr(username,'%'))) { *lp = 0; pstrcpy(password,lp+1); got_pass = True; - memset(strchr_m(opteq+1,'%')+1,'X',strlen(password)); + memset(strchr(opteq+1,'%')+1,'X',strlen(password)); } - if ((lp=strchr_m(username,'/'))) { + if ((lp=strchr(username,'/'))) { *lp = 0; pstrcpy(workgroup,lp+1); } @@ -808,6 +799,7 @@ static void parse_mount_smb(int argc, char **argv) { extern char *optarg; extern int optind; + static pstring servicesf = CONFIGFILE; char *p; DEBUGLEVEL = 1; @@ -815,27 +807,19 @@ static void parse_mount_smb(int argc, char **argv) /* here we are interactive, even if run from autofs */ setup_logging("mount.smbfs",True); -#if 0 /* JRA - Urban says not needed ? */ - /* CLI_FORCE_ASCII=false makes smbmount negotiate unicode. The default - is to not announce any unicode capabilities as current smbfs does - not support it. */ - p = getenv("CLI_FORCE_ASCII"); - if (p && !strcmp(p, "false")) - unsetenv("CLI_FORCE_ASCII"); - else - setenv("CLI_FORCE_ASCII", "true", 1); -#endif - + TimeInit(); + charset_initialise(); + in_client = True; /* Make sure that we tell lp_load we are */ if (getenv("USER")) { pstrcpy(username,getenv("USER")); - if ((p=strchr_m(username,'%'))) { + if ((p=strchr(username,'%'))) { *p = 0; pstrcpy(password,p+1); got_pass = True; - memset(strchr_m(getenv("USER"),'%')+1,'X',strlen(password)); + memset(strchr(getenv("USER"),'%')+1,'X',strlen(password)); } strupper(username); } @@ -854,9 +838,9 @@ static void parse_mount_smb(int argc, char **argv) pstrcpy(username,getenv("LOGNAME")); } - if (!lp_load(dyn_CONFIGFILE,True,False,False)) { + if (!lp_load(servicesf,True,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", - dyn_CONFIGFILE); + servicesf); } parse_mount_smb(argc, argv); @@ -867,6 +851,8 @@ static void parse_mount_smb(int argc, char **argv) DEBUG(3,("mount.smbfs started (version %s)\n", VERSION)); + codepage_initialise(lp_client_code_page()); + if (*workgroup == 0) { pstrcpy(workgroup,lp_workgroup()); } |