From 3a2f56cb630a7566ef0a70052b3102651bf653cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 25 Feb 2003 06:24:13 +0000 Subject: Fixed up some const related compiler warnings. (This used to be commit 923425e497112c5d1e2e569da6c13dcd02b6a8af) --- source3/client/client.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/client') diff --git a/source3/client/client.c b/source3/client/client.c index 5da12fd984..b95d4d877c 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -51,7 +51,8 @@ static int max_protocol = PROTOCOL_NT1; extern pstring user_socket_options; static int process_tok(fstring tok); -static int cmd_help(void); +static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, + const char **argv); /* 30 second timeout on most commands */ #define CLIENT_TIMEOUT (30*1000) @@ -979,7 +980,8 @@ static BOOL do_altname(char *name) /**************************************************************************** Exit client. ****************************************************************************/ -static int cmd_quit(void) +static NTSTATUS cmd_quit(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, + const char **argv) { cli_shutdown(cli); exit(0); @@ -2149,7 +2151,8 @@ static int process_tok(fstring tok) /**************************************************************************** help ****************************************************************************/ -static int cmd_help(void) +static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, + const char **argv) { int i=0,j; fstring buf; -- cgit From 64e53c9b22f23506acfd2fb4552b7c43129631a6 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 25 Feb 2003 23:28:28 +0000 Subject: Fix breakage done by myself yesterday. (This used to be commit f4492de2d668082df6ae06933d12a3cfe120d403) --- source3/client/client.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'source3/client') diff --git a/source3/client/client.c b/source3/client/client.c index b95d4d877c..5da12fd984 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -51,8 +51,7 @@ static int max_protocol = PROTOCOL_NT1; extern pstring user_socket_options; static int process_tok(fstring tok); -static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - const char **argv); +static int cmd_help(void); /* 30 second timeout on most commands */ #define CLIENT_TIMEOUT (30*1000) @@ -980,8 +979,7 @@ static BOOL do_altname(char *name) /**************************************************************************** Exit client. ****************************************************************************/ -static NTSTATUS cmd_quit(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - const char **argv) +static int cmd_quit(void) { cli_shutdown(cli); exit(0); @@ -2151,8 +2149,7 @@ static int process_tok(fstring tok) /**************************************************************************** help ****************************************************************************/ -static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - const char **argv) +static int cmd_help(void) { int i=0,j; fstring buf; -- cgit From 3042cfb7fabe25cc06e5cf6c49c2716c1112b6d2 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Mon, 3 Mar 2003 17:43:33 +0000 Subject: Do my janitorial duties to encourage others to do so. Fix lingering large offset problems in smbtar etc. (This used to be commit c416eec2f2a38eebfcda5868999d474628037f1e) --- source3/client/clitar.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'source3/client') diff --git a/source3/client/clitar.c b/source3/client/clitar.c index e8be5e04e7..74d901a2ca 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -959,9 +959,10 @@ static int skip_file(int skipsize) static int get_file(file_info2 finfo) { - int fnum = -1, pos = 0, dsize = 0, rsize = 0, bpos = 0; + int fnum = -1, pos = 0, dsize = 0, bpos = 0; + SMB_BIG_UINT rsize = 0; - DEBUG(5, ("get_file: file: %s, size %i\n", finfo.name, (int)finfo.size)); + DEBUG(5, ("get_file: file: %s, size %.0f\n", finfo.name, (double)finfo.size)); if (ensurepath(finfo.name) && (fnum=cli_open(cli, finfo.name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) == -1) { @@ -1052,7 +1053,7 @@ static int get_file(file_info2 finfo) ntarf++; - DEBUG(0, ("restore tar file %s of size %d bytes\n", finfo.name, (int)finfo.size)); + DEBUG(0, ("restore tar file %s of size %.0f bytes\n", finfo.name, (double)finfo.size)); return(True); } @@ -1082,18 +1083,18 @@ static int get_dir(file_info2 finfo) */ static char * get_longfilename(file_info2 finfo) { - int namesize = finfo.size + strlen(cur_dir) + 2; + int namesize = strlen(finfo.name) + strlen(cur_dir) + 2; char *longname = malloc(namesize); int offset = 0, left = finfo.size; BOOL first = True; DEBUG(5, ("Restoring a long file name: %s\n", finfo.name)); - DEBUG(5, ("Len = %d\n", (int)finfo.size)); + DEBUG(5, ("Len = %.0f\n", (double)finfo.size)); if (longname == NULL) { DEBUG(0, ("could not allocate buffer of size %d for longname\n", - (int)(finfo.size + strlen(cur_dir) + 2))); + namesize)); return(NULL); } -- cgit From 192148bab352697e625e78e7f2444e00453f35ff Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 6 Mar 2003 07:55:48 +0000 Subject: More safe_strcpy() off-by-one bug fixes. (mostly moves to pstrcpy()/fstrcpy()) Andrew Bartlett (This used to be commit 42b5514404bc7e33306c11344c6c934a1f83d295) --- source3/client/client.c | 6 +++--- source3/client/clitar.c | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 27 deletions(-) (limited to 'source3/client') diff --git a/source3/client/client.c b/source3/client/client.c index 5da12fd984..065cd2fcc9 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -2346,7 +2346,7 @@ static struct cli_state *do_connect(const char *server, const char *share) char *sharename; /* make a copy so we don't modify the global string 'service' */ - safe_strcpy(servicename, share, sizeof(servicename)-1); + fstrcpy(servicename, share); sharename = servicename; if (*sharename == '\\') { server = sharename+2; @@ -2621,9 +2621,9 @@ static int do_message_op(void) make_nmb_name(&calling, global_myname(), 0x0); make_nmb_name(&called , desthost, name_type); - safe_strcpy(server_name, desthost, sizeof(server_name)); + fstrcpy(server_name, desthost); snprintf(name_type_hex, sizeof(name_type_hex), "#%X", name_type); - safe_strcat(server_name, name_type_hex, sizeof(server_name)); + fstrcat(server_name, name_type_hex); zero_ip(&ip); if (have_ip) ip = dest_ip; diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 74d901a2ca..dfda997ca2 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -202,7 +202,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m /* write out a "standard" tar format header */ hb.dbuf.name[NAMSIZ-1]='\0'; - safe_strcpy(hb.dbuf.mode, amode, strlen(amode)); + safe_strcpy(hb.dbuf.mode, amode, sizeof(hb.dbuf.mode)-1); oct_it((SMB_BIG_UINT)0, 8, hb.dbuf.uid); oct_it((SMB_BIG_UINT)0, 8, hb.dbuf.gid); oct_it((SMB_BIG_UINT) size, 13, hb.dbuf.size); @@ -796,11 +796,11 @@ static void do_tar(file_info *finfo) DEBUG(5, ("Excl: strlen(cur_dir) = %d\n", (int)strlen(cur_dir))); - safe_strcpy(exclaim, cur_dir, sizeof(pstring)); + pstrcpy(exclaim, cur_dir); *(exclaim+strlen(exclaim)-1)='\0'; - safe_strcat(exclaim, "\\", sizeof(pstring)); - safe_strcat(exclaim, finfo->name, sizeof(exclaim)); + pstrcat(exclaim, "\\"); + pstrcat(exclaim, finfo->name); DEBUG(5, ("...tar_re_search: %d\n", tar_re_search)); @@ -820,12 +820,12 @@ static void do_tar(file_info *finfo) pstring saved_curdir; pstring mtar_mask; - safe_strcpy(saved_curdir, cur_dir, sizeof(saved_curdir)); + pstrcpy(saved_curdir, cur_dir); DEBUG(5, ("Sizeof(cur_dir)=%d, strlen(cur_dir)=%d, strlen(finfo->name)=%d\nname=%s,cur_dir=%s\n", (int)sizeof(cur_dir), (int)strlen(cur_dir), (int)strlen(finfo->name), finfo->name, cur_dir)); - safe_strcat(cur_dir,finfo->name, sizeof(cur_dir)); - safe_strcat(cur_dir,"\\", sizeof(cur_dir)); + pstrcat(cur_dir,finfo->name); + pstrcat(cur_dir,"\\"); DEBUG(5, ("Writing a dir, Name = %s\n", cur_dir)); @@ -836,16 +836,16 @@ static void do_tar(file_info *finfo) DEBUG(0,(" directory %s\n", cur_dir)); } ntarf++; /* Make sure we have a file on there */ - safe_strcpy(mtar_mask,cur_dir, sizeof(pstring)); - safe_strcat(mtar_mask,"*", sizeof(pstring)); + pstrcpy(mtar_mask,cur_dir); + pstrcat(mtar_mask,"*"); DEBUG(5, ("Doing list with mtar_mask: %s\n", mtar_mask)); do_list(mtar_mask, attribute, do_tar, False, True); - safe_strcpy(cur_dir,saved_curdir, sizeof(pstring)); + pstrcpy(cur_dir,saved_curdir); } else { - safe_strcpy(rname,cur_dir, sizeof(pstring)); - safe_strcat(rname,finfo->name, sizeof(pstring)); + pstrcpy(rname,cur_dir); + pstrcat(rname,finfo->name); do_atar(rname,finfo->name,finfo); } } @@ -1362,8 +1362,8 @@ int cmd_setmode(void) return 1; } - safe_strcpy(fname, cur_dir, sizeof(pstring)); - safe_strcat(fname, buf, sizeof(pstring)); + pstrcpy(fname, cur_dir); + pstrcat(fname, buf); while (next_token_nr(NULL,buf,NULL,sizeof(buf))) { q=buf; @@ -1459,32 +1459,32 @@ int process_tar(void) if (strrchr_m(cliplist[i], '\\')) { pstring saved_dir; - safe_strcpy(saved_dir, cur_dir, sizeof(pstring)); + pstrcpy(saved_dir, cur_dir); if (*cliplist[i]=='\\') { - safe_strcpy(tarmac, cliplist[i], sizeof(pstring)); + pstrcpy(tarmac, cliplist[i]); } else { - safe_strcpy(tarmac, cur_dir, sizeof(pstring)); - safe_strcat(tarmac, cliplist[i], sizeof(pstring)); + pstrcpy(tarmac, cur_dir); + pstrcat(tarmac, cliplist[i]); } - safe_strcpy(cur_dir, tarmac, sizeof(pstring)); + pstrcpy(cur_dir, tarmac); *(strrchr_m(cur_dir, '\\')+1)='\0'; DEBUG(5, ("process_tar, do_list with tarmac: %s\n", tarmac)); do_list(tarmac,attribute,do_tar, False, True); - safe_strcpy(cur_dir,saved_dir, sizeof(pstring)); + pstrcpy(cur_dir,saved_dir); } else { - safe_strcpy(tarmac, cur_dir, sizeof(pstring)); - safe_strcat(tarmac, cliplist[i], sizeof(pstring)); + pstrcpy(tarmac, cur_dir); + pstrcat(tarmac, cliplist[i]); DEBUG(5, ("process_tar, do_list with tarmac: %s\n", tarmac)); do_list(tarmac,attribute,do_tar, False, True); } } } else { pstring mask; - safe_strcpy(mask,cur_dir, sizeof(pstring)); + pstrcpy(mask,cur_dir); DEBUG(5, ("process_tar, do_list with mask: %s\n", mask)); - safe_strcat(mask,"\\*", sizeof(pstring)); + pstrcat(mask,"\\*"); do_list(mask,attribute,do_tar,False, True); } -- cgit From f944fd6975a598a154a943867c94f3dabc7a1139 Mon Sep 17 00:00:00 2001 From: Steve French Date: Fri, 7 Mar 2003 22:29:14 +0000 Subject: Add early prototype of cifs mount helper for Linux (This used to be commit b20bcf8d336b4b2079eb42342a96d1fe714709de) --- source3/client/mount.cifs.c | 389 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 389 insertions(+) create mode 100755 source3/client/mount.cifs.c (limited to 'source3/client') diff --git a/source3/client/mount.cifs.c b/source3/client/mount.cifs.c new file mode 100755 index 0000000000..5b19752f8b --- /dev/null +++ b/source3/client/mount.cifs.c @@ -0,0 +1,389 @@ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MOUNT_CIFS_VERSION "1" + +extern char *getusername(void); + +char * thisprogram; +int verboseflag = 0; +static int got_password = 0; +static int got_user = 0; +static char * user_name = NULL; +char * mountpassword = NULL; + + +void mount_cifs_usage() +{ + printf("\nUsage: %s remotetarget dir\n", thisprogram); + printf("\nMount the remotetarget, specified as either a UNC name or "); + printf(" CIFS URL, to the local directory, dir.\n"); + + return; +} + +/* caller frees username if necessary */ +char * getusername() { + char *username = NULL; + struct passwd *password = getpwuid(getuid()); + + if (password) { + username = password->pw_name; + } + return username; +} + +char * parse_cifs_url(unc_name) +{ + printf("\ncifs url %s\n",unc_name); +} + +char * parse_options(char * options) +{ + /* BB add missing code BB */ +} + +/* Note that caller frees the returned buffer if necessary */ +char * parse_server(char * unc_name) +{ + int length = strnlen(unc_name,1024); + char * share; + char * ipaddress_string = NULL; + struct hostent * host_entry; + struct in_addr server_ipaddr; + int rc,j; + char temp[64]; + + + if(length > 1023) { + printf("mount error: UNC name too long"); + return 0; + } + if (strncasecmp("cifs://",unc_name,7) == 0) + return parse_cifs_url(unc_name+7); + if (strncasecmp("smb://",unc_name,6) == 0) { + return parse_cifs_url(unc_name+6); + } + + if(length < 3) { + /* BB add code to find DFS root here */ + printf("\nMounting the DFS root for domain not implemented yet"); + return 0; + } else { + /* BB add support for \\\\ not just // */ + if(strncmp(unc_name,"//",2) && strncmp(unc_name,"\\\\",2)) { + printf("mount error: improperly formatted UNC name."); + printf(" %s does not begin with \\\\ or //\n",unc_name); + return 0; + } else { + unc_name += 2; + if (share = strchr(unc_name, '/')) { + *share = 0; /* temporarily terminate the string */ + share += 1; + host_entry = gethostbyname(unc_name); + *(share - 1) = '\\'; /* put the slash back */ +/* rc = getipnodebyname(unc_name, AF_INET, AT_ADDRCONFIG ,&rc);*/ + if(host_entry == NULL) { + printf("mount error: could not find target server. TCP name %s not found ", unc_name); + printf(" rc = %d\n",rc); + return 0; + } + else { + printf("Target server %s %x found\n",host_entry->h_name,host_entry->h_addr); /* BB removeme */ + /* BB should we pass an alternate version of the share name as Unicode */ + /* BB what about ipv6? BB */ + /* BB add retries with alternate servers in list */ + + memcpy(&server_ipaddr.s_addr, host_entry->h_addr, 4); + + ipaddress_string = inet_ntoa(server_ipaddr); + if(ipaddress_string == NULL) { + printf("mount error: could not get valid ip address for target server\n"); + return 0; + } + return ipaddress_string; + } + } else { + /* BB add code to find DFS root (send null path on get DFS Referral to specified server here */ + printf("Mounting the DFS root for a particular server not implemented yet\n"); + return 0; + } + } + } +} + +static struct option longopts[] = { + { "all", 0, 0, 'a' }, + { "help", 0, 0, 'h' }, + { "read-only", 0, 0, 'r' }, + { "ro", 0, 0, 'r' }, + { "verbose", 0, 0, 'v' }, + { "version", 0, 0, 'V' }, + { "read-write", 0, 0, 'w' }, + { "rw", 0, 0, 'w' }, + { "options", 1, 0, 'o' }, + { "types", 1, 0, 't' }, + { "replace", 0, 0, 129 }, + { "after", 0, 0, 130 }, + { "before", 0, 0, 131 }, + { "over", 0, 0, 132 }, + { "move", 0, 0, 133 }, + { "rsize",1, 0, 136 }, + { "wsize",1, 0, 137 }, + { "uid", 1, 0, 138}, + { "gid", 1, 0, 139}, + { "uuid",1,0,'U' }, + { "user",1,0,140}, + { "username",1,0,140}, + { "dom",1,0,141}, + { "domain",1,0,141}, + { "password",1,0,142}, + { NULL, 0, 0, 0 } +}; + +int main(int argc, char ** argv) +{ + int c; + int flags = MS_MANDLOCK | MS_MGC_VAL; + char * orgoptions = NULL; + char * options; + char * share_name; + char * domain_name = NULL; + char * ipaddr; + char * mount_point; + char * uuid = NULL; + int rc,i; + int rsize = 0; + int wsize = 0; + int nomtab = 0; + int uid = 0; + int gid = 0; + int optlen = 0; + struct stat statbuf; + struct utsname sysinfo; + + /* setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); */ + + if(argc && argv) { + thisprogram = argv[0]; + } + if(thisprogram == NULL) + thisprogram = "mount.cifs"; + + uname(&sysinfo); +#ifdef _GNU_SOURCE + printf(" node: %s machine: %s\n", sysinfo.nodename,sysinfo.machine); +#endif + mount_cifs_usage(); + share_name = argv[1]; + mount_point = argv[2]; + /* add sharename in opts string as unc= parm */ + + while ((c = getopt_long (argc, argv, "afFhilL:no:O:rsU:vVwt:", + longopts, NULL)) != -1) { + switch (c) { +/* case 'a': + ++mount_all; + break; + case 'f': + ++fake; + break; + case 'F': + ++optfork; + break; */ + case 'h': /* help */ + mount_cifs_usage (); + break; +/* case 'i': + external_allowed = 0; + break; + case 'l': + list_with_volumelabel = 1; + break; + case 'L': + volumelabel = optarg; + break; */ + case 'n': + ++nomtab; + break; + case 'o': + if (orgoptions) { + orgoptions = strcat(orgoptions, ","); + orgoptions = strcat(orgoptions,optarg); + } else + orgoptions = strdup(optarg); + break; + +/* case 'O': + if (test_opts) + test_opts = xstrconcat3(test_opts, ",", optarg); + else + test_opts = xstrdup(optarg); + break;*/ + case 'r': /* mount readonly */ + flags |= MS_RDONLY;; + break; + case 'U': + uuid = optarg; + break; + case 'v': + ++verboseflag; + break; +/* case 'V': + printf ("mount: %s\n", version); + exit (0);*/ + case 'w': + flags &= ~MS_RDONLY;; + break; +/* case 0: + break; + + case 128: + mounttype = MS_BIND; + break; + case 129: + mounttype = MS_REPLACE; + break; + case 130: + mounttype = MS_AFTER; + break; + case 131: + mounttype = MS_BEFORE; + break; + case 132: + mounttype = MS_OVER; + break; + case 133: + mounttype = MS_MOVE; + break; + case 135: + mounttype = (MS_BIND | MS_REC); + break; */ + case 136: + rsize = atoi(optarg) ; + break; + case 137: + wsize = atoi(optarg); + break; + case 138: + uid = atoi(optarg); + break; + case 139: + gid = atoi(optarg); + break; + case 140: + got_user = 1; + user_name = optarg; + break; + case 141: + domain_name = optarg; + break; + case 142: + got_password = 1; + mountpassword = optarg; + break; + case '?': + default: + mount_cifs_usage (); + } + } + + for(i = 0;i < argc;i++) /* BB remove */ + printf("\narg %d is %s",i,argv[i]); /* BB remove */ + printf("\n"); /* BB removeme */ + + /* canonicalize the path in argv[1]? */ + + if(stat (mount_point, &statbuf)) { + printf("mount error: mount point %s does not exist\n",mount_point); + return -1; + } + if (S_ISDIR(statbuf.st_mode) == 0) { + printf("mount error: mount point %s is not a directory\n",mount_point); + return -1; + } + + if(geteuid()) { + printf("mount error: permission denied, not superuser and cifs.mount not installed SUID\n"); + return -1; + } + + ipaddr = parse_server(share_name); +/* if(share_name == NULL) + return 1; */ + parse_options(orgoptions); + + if(got_user == 0) + user_name = getusername(); + +/* check username for user%password format */ + + if(got_password == 0) { + if (getenv("PASSWD")) { + mountpassword = malloc(33); + if(mountpassword) { + strncpy(mountpassword,getenv("PASSWD"),32); + got_password = 1; + } +/* } else if (getenv("PASSWD_FD") || getenv("PASSWD_FILE")) { + get_password_file(); + got_password = 1;*/ /* BB add missing function */ + } else { + mountpassword = getpass("Password: "); /* BB obsolete */ + got_password = 1; + } + } + + /* launch daemon (handles dfs name resolution and credential change) */ + if(orgoptions) + optlen = strlen(orgoptions); + else + optlen = 0; + options = malloc(optlen + 25 + strlen(share_name) + strlen(user_name) + + strlen(ipaddr) + 1); + strcpy(options,"unc="); + strcat(options,share_name); + strncat(options,",ip=",4); + strcat(options,ipaddr); + strncat(options,",user=",6); + strcat(options,user_name); + strncat(options,",pass=",6); + strcat(options,mountpassword); + strncat(options,",ver=",5); + strcat(options,MOUNT_CIFS_VERSION); + if(optlen) + strcat(options,orgoptions); + printf("\noptions %s \n",options); + if(mount(share_name, mount_point, "cifs", flags, options)) { + /* remember to kill daemon on error */ + switch (errno) { + case 0: + printf(" success\n"); /* BB removeme */ + return 0; + case ENODEV: + printf("mount error: cifs filesystem not supported by the system\n"); + break; + default: + printf("mount error %d = %s",errno,strerror(errno)); + } + printf("\nRefer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n"); + return -1; + } else + printf(" mount succeeded\n"); /* BB removeme */ +} + -- cgit From 01289b14a7cbe0e1a1e135349037b0e7ba5fe70b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 8 Mar 2003 10:22:50 +0000 Subject: Make sure that the 'remote' machine name can only be set once. For some weird reason, during a Win2003 installation, when you select 'domain join' it sends one machine name in the name exchange, and litraly 'machinename' during the NTLMSSP login. Also fix up winbindd's logfile handling, so that it matches smbd and nmbd. (This helps me, by seperating the logs by pid). Andrew Bartlett (This used to be commit afe5a3832f79131fb74461577f1db0e5e8bf4b6d) --- source3/client/smbmount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client') diff --git a/source3/client/smbmount.c b/source3/client/smbmount.c index e2372d02b4..98302485e4 100644 --- a/source3/client/smbmount.c +++ b/source3/client/smbmount.c @@ -398,7 +398,7 @@ 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 ... */ + set_remote_machine_name("smbmount", False); /* sneaky ... */ setup_logging("mount.smbfs", False); reopen_logs(); DEBUG(0, ("mount.smbfs: entering daemon mode for service %s, pid=%d\n", the_service, sys_getpid())); -- cgit From 58abc7b5b623e19d81586db4ae834c8e18e83082 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 15 Mar 2003 06:50:45 +0000 Subject: If the server went away, don't segfault by attempting to FD_SET -1. Andrew Bartlett (This used to be commit 4b1337ee94a19e39a2f4012c4dbc32a2e58cacf5) --- source3/client/client.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/client') diff --git a/source3/client/client.c b/source3/client/client.c index 065cd2fcc9..99fc779a9e 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -2269,6 +2269,9 @@ static void readline_callback(void) last_t = t; + if (cli->fd == -1) + return; + again: FD_ZERO(&fds); FD_SET(cli->fd,&fds); -- cgit From 2055e724ada91865ba00b2d79bc0737504ea761d Mon Sep 17 00:00:00 2001 From: Steve French Date: Sat, 15 Mar 2003 22:35:47 +0000 Subject: Checkin cifs vfs for Linux mount helper (This used to be commit a55acfd7a296c5ae9b043dc03393a29d87e43a40) --- source3/client/mount.cifs.c | 254 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 211 insertions(+), 43 deletions(-) (limited to 'source3/client') diff --git a/source3/client/mount.cifs.c b/source3/client/mount.cifs.c index 5b19752f8b..7167859d7b 100755 --- a/source3/client/mount.cifs.c +++ b/source3/client/mount.cifs.c @@ -13,6 +13,7 @@ #include #include #include +#include #define MOUNT_CIFS_VERSION "1" @@ -22,6 +23,11 @@ char * thisprogram; int verboseflag = 0; static int got_password = 0; static int got_user = 0; +static int got_domain = 0; +static int got_ip = 0; +static int got_unc = 0; +static int got_uid = 0; +static int got_gid = 0; static char * user_name = NULL; char * mountpassword = NULL; @@ -32,7 +38,7 @@ void mount_cifs_usage() printf("\nMount the remotetarget, specified as either a UNC name or "); printf(" CIFS URL, to the local directory, dir.\n"); - return; + exit(1); } /* caller frees username if necessary */ @@ -51,9 +57,137 @@ char * parse_cifs_url(unc_name) printf("\ncifs url %s\n",unc_name); } -char * parse_options(char * options) +int parse_options(char * options) { - /* BB add missing code BB */ + char * data; + char * value = 0; + + if (!options) + return 1; + + while ((data = strsep(&options, ",")) != NULL) { + if (!*data) + continue; + if ((value = strchr(data, '=')) != NULL) { + *value++ = '\0'; + } + if (strncmp(data, "user", 4) == 0) { + if (!value || !*value) { + printf("invalid or missing username\n"); + return 1; /* needs_arg; */ + } + if (strnlen(value, 260) < 260) { + got_user=1; + /* BB add check for format user%pass */ + /* if(strchr(username%passw) got_password = 1) */ + } else { + printf("username too long\n"); + return 1; + } + } else if (strncmp(data, "pass", 4) == 0) { + if (!value || !*value) { + if(got_password) { + printf("password specified twice, ignoring second\n"); + } else + got_password = 1; + } else if (strnlen(value, 17) < 17) { + got_password = 1; + } else { + printf("password too long\n"); + return 1; + } + } else if (strncmp(data, "ip", 2) == 0) { + if (!value || !*value) { + printf("target ip address argument missing"); + } else if (strnlen(value, 35) < 35) { + got_ip = 1; + } else { + printf("ip address too long\n"); + return 1; + } + } else if ((strncmp(data, "unc", 3) == 0) + || (strncmp(data, "target", 6) == 0) + || (strncmp(data, "path", 4) == 0)) { + if (!value || !*value) { + printf("invalid path to network resource\n"); + return 1; /* needs_arg; */ + } else if(strnlen(value,5) < 5) { + printf("UNC name too short"); + } + + if (strnlen(value, 300) < 300) { + got_unc = 1; + if (strncmp(value, "//", 2) == 0) { + if(got_unc) + printf("unc name specified twice, ignoring second\n"); + else + got_unc = 1; + } else if (strncmp(value, "\\\\", 2) != 0) { + printf("UNC Path does not begin with // or \\\\ \n"); + return 1; + } else { + if(got_unc) + printf("unc name specified twice, ignoring second\n"); + else + got_unc = 1; + } + } else { + printf("CIFS: UNC name too long\n"); + return 1; + } + } else if ((strncmp(data, "domain", 3) == 0) + || (strncmp(data, "workgroup", 5) == 0)) { + if (!value || !*value) { + printf("CIFS: invalid domain name\n"); + return 1; /* needs_arg; */ + } + if (strnlen(value, 65) < 65) { + got_domain = 1; + } else { + printf("domain name too long\n"); + return 1; + } + } else if (strncmp(data, "uid", 3) == 0) { + if (value && *value) { + got_uid = 1; + } + } else if (strncmp(data, "gid", 3) == 0) { + if (value && *value) { + got_gid = 1; + } + } /* else if (strnicmp(data, "file_mode", 4) == 0) { + if (value && *value) { + vol->file_mode = + simple_strtoul(value, &value, 0); + } + } else if (strnicmp(data, "dir_mode", 3) == 0) { + if (value && *value) { + vol->dir_mode = + simple_strtoul(value, &value, 0); + } + } else if (strnicmp(data, "port", 4) == 0) { + if (value && *value) { + vol->port = + simple_strtoul(value, &value, 0); + } + } else if (strnicmp(data, "rsize", 5) == 0) { + if (value && *value) { + vol->rsize = + simple_strtoul(value, &value, 0); + } + } else if (strnicmp(data, "wsize", 5) == 0) { + if (value && *value) { + vol->wsize = + simple_strtoul(value, &value, 0); + } + } else if (strnicmp(data, "version", 3) == 0) { + + } else if (strnicmp(data, "rw", 2) == 0) { + + } else + printf("CIFS: Unknown mount option %s\n",data); */ + } + return 0; } /* Note that caller frees the returned buffer if necessary */ @@ -67,7 +201,6 @@ char * parse_server(char * unc_name) int rc,j; char temp[64]; - if(length > 1023) { printf("mount error: UNC name too long"); return 0; @@ -89,8 +222,11 @@ char * parse_server(char * unc_name) printf(" %s does not begin with \\\\ or //\n",unc_name); return 0; } else { + unc_name[0] = '\\'; + unc_name[1] = '\\'; unc_name += 2; - if (share = strchr(unc_name, '/')) { + if ((share = strchr(unc_name, '/')) || + (share = strchr(unc_name,'\\'))) { *share = 0; /* temporarily terminate the string */ share += 1; host_entry = gethostbyname(unc_name); @@ -102,7 +238,6 @@ char * parse_server(char * unc_name) return 0; } else { - printf("Target server %s %x found\n",host_entry->h_name,host_entry->h_addr); /* BB removeme */ /* BB should we pass an alternate version of the share name as Unicode */ /* BB what about ipv6? BB */ /* BB add retries with alternate servers in list */ @@ -159,12 +294,12 @@ int main(int argc, char ** argv) int c; int flags = MS_MANDLOCK | MS_MGC_VAL; char * orgoptions = NULL; - char * options; - char * share_name; + char * share_name = NULL; char * domain_name = NULL; - char * ipaddr; - char * mount_point; + char * ipaddr = NULL; char * uuid = NULL; + char * mountpoint; + char * options; int rc,i; int rsize = 0; int wsize = 0; @@ -174,6 +309,8 @@ int main(int argc, char ** argv) int optlen = 0; struct stat statbuf; struct utsname sysinfo; + struct mntent mountent; + FILE * pmntfile; /* setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -186,12 +323,14 @@ int main(int argc, char ** argv) thisprogram = "mount.cifs"; uname(&sysinfo); -#ifdef _GNU_SOURCE + /* BB add workstation name and domain and pass down */ +/*#ifdef _GNU_SOURCE printf(" node: %s machine: %s\n", sysinfo.nodename,sysinfo.machine); -#endif - mount_cifs_usage(); +#endif*/ + if(argc < 3) + mount_cifs_usage(); share_name = argv[1]; - mount_point = argv[2]; + mountpoint = argv[2]; /* add sharename in opts string as unc= parm */ while ((c = getopt_long (argc, argv, "afFhilL:no:O:rsU:vVwt:", @@ -291,7 +430,7 @@ int main(int argc, char ** argv) user_name = optarg; break; case 141: - domain_name = optarg; + domain_name = optarg; break; case 142: got_password = 1; @@ -303,18 +442,14 @@ int main(int argc, char ** argv) } } - for(i = 0;i < argc;i++) /* BB remove */ - printf("\narg %d is %s",i,argv[i]); /* BB remove */ - printf("\n"); /* BB removeme */ - /* canonicalize the path in argv[1]? */ - if(stat (mount_point, &statbuf)) { - printf("mount error: mount point %s does not exist\n",mount_point); + if(stat (mountpoint, &statbuf)) { + printf("mount error: mount point %s does not exist\n",mountpoint); return -1; } if (S_ISDIR(statbuf.st_mode) == 0) { - printf("mount error: mount point %s is not a directory\n",mount_point); + printf("mount error: mount point %s is not a directory\n",mountpoint); return -1; } @@ -326,7 +461,8 @@ int main(int argc, char ** argv) ipaddr = parse_server(share_name); /* if(share_name == NULL) return 1; */ - parse_options(orgoptions); + if (parse_options(strdup(orgoptions))) + return 1; if(got_user == 0) user_name = getusername(); @@ -348,32 +484,50 @@ int main(int argc, char ** argv) got_password = 1; } } - - /* launch daemon (handles dfs name resolution and credential change) */ - if(orgoptions) + /* FIXME launch daemon (handles dfs name resolution and credential change) + remember to clear parms and overwrite password field before launching */ + if(orgoptions) { optlen = strlen(orgoptions); - else + } else optlen = 0; - options = malloc(optlen + 25 + strlen(share_name) + strlen(user_name) - + strlen(ipaddr) + 1); - strcpy(options,"unc="); + if(share_name) + optlen += strlen(share_name) + 4; + if(user_name) + optlen += strlen(user_name) + 6; + if(ipaddr) + optlen += strlen(ipaddr) + 4; + if(mountpassword) + optlen += strlen(mountpassword) + 6; + options = malloc(optlen + 10); + + options[0] = 0; + strncat(options,"unc=",4); strcat(options,share_name); - strncat(options,",ip=",4); - strcat(options,ipaddr); - strncat(options,",user=",6); - strcat(options,user_name); - strncat(options,",pass=",6); - strcat(options,mountpassword); + if(ipaddr) { + strncat(options,",ip=",4); + strcat(options,ipaddr); + } + if(user_name) { + strncat(options,",user=",6); + strcat(options,user_name); + } + if(mountpassword) { + strncat(options,",pass=",6); + strcat(options,mountpassword); + } strncat(options,",ver=",5); strcat(options,MOUNT_CIFS_VERSION); - if(optlen) + + if(orgoptions) { + strcat(options,","); strcat(options,orgoptions); - printf("\noptions %s \n",options); - if(mount(share_name, mount_point, "cifs", flags, options)) { + } + /* printf("\noptions %s \n",options);*/ + if(mount(share_name, mountpoint, "cifs", flags, options)) { /* remember to kill daemon on error */ switch (errno) { case 0: - printf(" success\n"); /* BB removeme */ + printf("mount failed but no error number set\n"); return 0; case ENODEV: printf("mount error: cifs filesystem not supported by the system\n"); @@ -381,9 +535,23 @@ int main(int argc, char ** argv) default: printf("mount error %d = %s",errno,strerror(errno)); } - printf("\nRefer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n"); + printf("Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n"); return -1; - } else - printf(" mount succeeded\n"); /* BB removeme */ + } else { + pmntfile = setmntent(MOUNTED, "a+"); + if(pmntfile) { + mountent.mnt_fsname = share_name; + mountent.mnt_dir = mountpoint; + mountent.mnt_type = "cifs"; + mountent.mnt_opts = ""; + mountent.mnt_freq = 0; + mountent.mnt_passno = 0; + rc = addmntent(pmntfile,&mountent); + endmntent(pmntfile); + } else { + printf("could not update mount table\n"); + } + } + return 0; } -- cgit From 400bb4bfab01a6c262b15658dee5c0d011d0e883 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 16 Mar 2003 13:21:12 +0000 Subject: - Make ReadDirName return a const char*. - Consequential changes from that - mark our fstring/pstring assumptions in function prototypes Andrew Bartlett (This used to be commit fe2bc64bc439b27387b8f326b0f4f3bfcc3d04a1) --- source3/client/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/client') diff --git a/source3/client/client.c b/source3/client/client.c index 99fc779a9e..1248c25659 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -1291,7 +1291,7 @@ static int file_find(struct file_list **list, const char *directory, int ret; char *path; BOOL isdir; - char *dname; + const char *dname; dir = opendir(directory); if (!dir) return -1; -- cgit