diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-10-21 14:51:13 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-10-21 14:51:13 +0200 |
commit | 5209a846a9157e649fcdcb561f7eaf19c8c0e465 (patch) | |
tree | b0a7e52b5646c8eec182dbc391e7934b6804488c /source3/client | |
parent | 625359b2e266105022309df8985720108ecd6f67 (diff) | |
parent | 2ee8d29d22bcb1c350ab59d71b0aee548489bc9c (diff) | |
download | samba-5209a846a9157e649fcdcb561f7eaf19c8c0e465.tar.gz samba-5209a846a9157e649fcdcb561f7eaf19c8c0e465.tar.bz2 samba-5209a846a9157e649fcdcb561f7eaf19c8c0e465.zip |
Merge branch 'master' of ssh://git.samba.org/data/git/samba into regsrv
Conflicts:
source4/lib/registry/ldb.c
source4/rpc_server/winreg/rpc_winreg.c
Diffstat (limited to 'source3/client')
-rw-r--r-- | source3/client/client.c | 42 | ||||
-rw-r--r-- | source3/client/clitar.c | 28 | ||||
-rw-r--r-- | source3/client/mount.cifs.c | 96 | ||||
-rw-r--r-- | source3/client/smbspool.c | 2 |
4 files changed, 100 insertions, 68 deletions
diff --git a/source3/client/client.c b/source3/client/client.c index 1c05c4035d..26badc4051 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -84,9 +84,9 @@ static struct sockaddr_storage dest_ss; static bool abort_mget = true; /* timing globals */ -SMB_BIG_UINT get_total_size = 0; +uint64_t get_total_size = 0; unsigned int get_total_time_ms = 0; -static SMB_BIG_UINT put_total_size = 0; +static uint64_t put_total_size = 0; static unsigned int put_total_time_ms = 0; /* totals globals */ @@ -1203,7 +1203,7 @@ static void do_mget(file_info *finfo, const char *dir) strlower_m(finfo->name); } - if (!directory_exist(finfo->name,NULL) && + if (!directory_exist(finfo->name) && mkdir(finfo->name,0777) != 0) { d_printf("failed to create directory %s\n",finfo->name); client_set_cur_dir(saved_curdir); @@ -1752,7 +1752,7 @@ static int cmd_put(void) SMB_STRUCT_STAT st; /* allow '-' to represent stdin jdblair, 24.jun.98 */ - if (!file_exist(lname,&st) && + if (!file_exist_stat(lname,&st) && (strcmp(lname,"-"))) { d_printf("%s does not exist\n",lname); return 1; @@ -2555,7 +2555,7 @@ static int cmd_lock(void) { TALLOC_CTX *ctx = talloc_tos(); char *buf = NULL; - SMB_BIG_UINT start, len; + uint64_t start, len; enum brl_type lock_type; int fnum; @@ -2584,14 +2584,14 @@ static int cmd_lock(void) return 1; } - start = (SMB_BIG_UINT)strtol(buf, (char **)NULL, 16); + start = (uint64_t)strtol(buf, (char **)NULL, 16); if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n"); return 1; } - len = (SMB_BIG_UINT)strtol(buf, (char **)NULL, 16); + len = (uint64_t)strtol(buf, (char **)NULL, 16); if (!cli_posix_lock(cli, fnum, start, len, true, lock_type)) { d_printf("lock failed %d: %s\n", fnum, cli_errstr(cli)); @@ -2604,7 +2604,7 @@ static int cmd_unlock(void) { TALLOC_CTX *ctx = talloc_tos(); char *buf = NULL; - SMB_BIG_UINT start, len; + uint64_t start, len; int fnum; if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { @@ -2618,14 +2618,14 @@ static int cmd_unlock(void) return 1; } - start = (SMB_BIG_UINT)strtol(buf, (char **)NULL, 16); + start = (uint64_t)strtol(buf, (char **)NULL, 16); if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { d_printf("unlock <fnum> <hex-start> <hex-len>\n"); return 1; } - len = (SMB_BIG_UINT)strtol(buf, (char **)NULL, 16); + len = (uint64_t)strtol(buf, (char **)NULL, 16); if (!cli_posix_unlock(cli, fnum, start, len)) { d_printf("unlock failed %d: %s\n", fnum, cli_errstr(cli)); @@ -3038,7 +3038,7 @@ static int cmd_getfacl(void) break; case SMB_POSIX_ACL_GROUP: uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)+2); - d_printf("group:%u", uorg); + d_printf("group:%u:", uorg); break; case SMB_POSIX_ACL_MASK: d_printf("mask::"); @@ -3075,7 +3075,7 @@ static int cmd_getfacl(void) break; case SMB_POSIX_ACL_GROUP: uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)+2); - d_printf("default:group:%u", uorg); + d_printf("default:group:%u:", uorg); break; case SMB_POSIX_ACL_MASK: d_printf("default:mask::"); @@ -3566,7 +3566,7 @@ static int cmd_reput(void) return 1; } - if (!file_exist(local_name, &st)) { + if (!file_exist_stat(local_name, &st)) { d_printf("%s does not exist\n", local_name); return 1; } @@ -4345,6 +4345,8 @@ cleanup: } } +static bool finished; + /**************************************************************************** Make sure we swallow keepalives during idle time. ****************************************************************************/ @@ -4391,6 +4393,8 @@ static void readline_callback(void) DEBUG(0, ("Read from server failed, maybe it closed " "the connection\n")); + finished = true; + smb_readline_done(); if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { set_smb_read_error(&cli->smb_rw_error, SMB_READ_EOF); @@ -4417,9 +4421,17 @@ static void readline_callback(void) /* Ping the server to keep the connection alive using SMBecho. */ { + NTSTATUS status; unsigned char garbage[16]; memset(garbage, 0xf0, sizeof(garbage)); - cli_echo(cli, 1, data_blob_const(garbage, sizeof(garbage))); + status = cli_echo(cli, 1, data_blob_const(garbage, sizeof(garbage))); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("SMBecho failed. Maybe server has closed " + "the connection\n")); + finished = true; + smb_readline_done(); + } } } @@ -4431,7 +4443,7 @@ static int process_stdin(void) { int rc = 0; - while (1) { + while (!finished) { TALLOC_CTX *frame = talloc_stackframe(); char *tok = NULL; char *the_prompt = NULL; diff --git a/source3/client/clitar.c b/source3/client/clitar.c index 084f87e399..7ad8a73e9c 100644 --- a/source3/client/clitar.c +++ b/source3/client/clitar.c @@ -112,11 +112,11 @@ extern int get_total_size; static int blocksize=20; static int tarhandle; -static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t mtime, +static void writetarheader(int f, const char *aname, uint64_t size, time_t mtime, const char *amode, unsigned char ftype); static void do_atar(const char *rname_in,char *lname,file_info *finfo1); static void do_tar(file_info *finfo, const char *dir); -static void oct_it(SMB_BIG_UINT value, int ndgs, char *p); +static void oct_it(uint64_t value, int ndgs, char *p); static void fixtarname(char *tptr, const char *fp, size_t l); static int dotarbuf(int f, char *b, int n); static void dozerobuf(int f, int n); @@ -154,7 +154,7 @@ static char *string_create_s(int size) Write a tar header to buffer ****************************************************************************/ -static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t mtime, +static void writetarheader(int f, const char *aname, uint64_t size, time_t mtime, const char *amode, unsigned char ftype) { union hblock hb; @@ -195,10 +195,10 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m hb.dbuf.name[NAMSIZ-1]='\0'; 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); - if (size > (SMB_BIG_UINT)077777777777LL) { + oct_it((uint64_t)0, 8, hb.dbuf.uid); + oct_it((uint64_t)0, 8, hb.dbuf.gid); + oct_it((uint64_t) size, 13, hb.dbuf.size); + if (size > (uint64_t)077777777777LL) { /* This is a non-POSIX compatible extention to store files greater than 8GB. */ @@ -207,7 +207,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m for (i = 8, jp=(char*)&size; i; i--) hb.dbuf.size[i+3] = *(jp++); } - oct_it((SMB_BIG_UINT) mtime, 13, hb.dbuf.mtime); + oct_it((uint64_t) mtime, 13, hb.dbuf.mtime); memcpy(hb.dbuf.chksum, " ", sizeof(hb.dbuf.chksum)); memset(hb.dbuf.linkname, 0, NAMSIZ); hb.dbuf.linkflag=ftype; @@ -215,7 +215,7 @@ static void writetarheader(int f, const char *aname, SMB_BIG_UINT size, time_t m for (chk=0, i=sizeof(hb.dummy), jp=hb.dummy; --i>=0;) chk+=(0xFF & *jp++); - oct_it((SMB_BIG_UINT) chk, 8, hb.dbuf.chksum); + oct_it((uint64_t) chk, 8, hb.dbuf.chksum); hb.dbuf.chksum[6] = '\0'; (void) dotarbuf(f, hb.dummy, sizeof(hb.dummy)); @@ -431,7 +431,7 @@ static void fixtarname(char *tptr, const char *fp, size_t l) Convert from decimal to octal string ****************************************************************************/ -static void oct_it (SMB_BIG_UINT value, int ndgs, char *p) +static void oct_it (uint64_t value, int ndgs, char *p) { /* Converts long to octal string, pads with leading zeros */ @@ -567,7 +567,7 @@ static bool ensurepath(const char *fname) return True; } -static int padit(char *buf, SMB_BIG_UINT bufsize, SMB_BIG_UINT padsize) +static int padit(char *buf, uint64_t bufsize, uint64_t padsize) { int berr= 0; int bytestowrite; @@ -607,7 +607,7 @@ append one remote file to the tar file static void do_atar(const char *rname_in,char *lname,file_info *finfo1) { int fnum = -1; - SMB_BIG_UINT nread=0; + uint64_t nread=0; char ftype; file_info2 finfo; bool shallitime=True; @@ -738,7 +738,7 @@ static void do_atar(const char *rname_in,char *lname,file_info *finfo1) if (nread < finfo.size) { DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n", (double)finfo.size, (int)nread)); - if (padit(data, (SMB_BIG_UINT)sizeof(data), finfo.size - nread)) + if (padit(data, (uint64_t)sizeof(data), finfo.size - nread)) DEBUG(0,("Error writing tar file - %s\n", strerror(errno))); } @@ -992,7 +992,7 @@ static int skip_file(int skipsize) static int get_file(file_info2 finfo) { int fnum = -1, pos = 0, dsize = 0, bpos = 0; - SMB_BIG_UINT rsize = 0; + uint64_t rsize = 0; DEBUG(5, ("get_file: file: %s, size %.0f\n", finfo.name, (double)finfo.size)); diff --git a/source3/client/mount.cifs.c b/source3/client/mount.cifs.c index 3b56e5f861..fd8014cf9f 100644 --- a/source3/client/mount.cifs.c +++ b/source3/client/mount.cifs.c @@ -56,6 +56,10 @@ #endif /* _SAMBA_BUILD_ */ #endif /* MOUNT_CIFS_VENDOR_SUFFIX */ +#ifdef _SAMBA_BUILD_ +#include "include/config.h" +#endif + #ifndef MS_MOVE #define MS_MOVE 8192 #endif @@ -75,6 +79,15 @@ #define MOUNT_PASSWD_SIZE 64 #define DOMAIN_SIZE 64 +/* exit status - bits below are ORed */ +#define EX_USAGE 1 /* incorrect invocation or permission */ +#define EX_SYSERR 2 /* out of memory, cannot fork, ... */ +#define EX_SOFTWARE 4 /* internal mount bug or wrong version */ +#define EX_USER 8 /* user interrupt */ +#define EX_FILEIO 16 /* problems writing, locking, ... mtab/fstab */ +#define EX_FAIL 32 /* mount failure */ +#define EX_SOMEOK 64 /* some mount succeeded */ + const char *thisprogram; int verboseflag = 0; static int got_password = 0; @@ -94,6 +107,8 @@ char * prefixpath = NULL; /* like strncpy but does not 0 fill the buffer and always null * terminates. bufsize is the size of the destination buffer */ + +#ifndef HAVE_STRLCPY static size_t strlcpy(char *d, const char *s, size_t bufsize) { size_t len = strlen(s); @@ -104,10 +119,13 @@ static size_t strlcpy(char *d, const char *s, size_t bufsize) d[len] = 0; return ret; } +#endif /* like strncat but does not 0 fill the buffer and always null * terminates. bufsize is the length of the buffer, which should * be one more than the maximum resulting string length */ + +#ifndef HAVE_STRLCAT static size_t strlcat(char *d, const char *s, size_t bufsize) { size_t len1 = strlen(d); @@ -126,6 +144,7 @@ static size_t strlcat(char *d, const char *s, size_t bufsize) } return ret; } +#endif /* BB finish BB @@ -164,7 +183,7 @@ static void mount_cifs_usage(void) printf("\n\t%s -V\n",thisprogram); SAFE_FREE(mountpassword); - exit(1); + exit(EX_USAGE); } /* caller frees username if necessary */ @@ -223,7 +242,7 @@ static int open_cred_file(char * file_name) if(length > 4086) { printf("mount.cifs failed due to malformed username in credentials file"); memset(line_buf,0,4096); - exit(1); + exit(EX_USAGE); } else { got_user = 1; user_name = (char *)calloc(1 + length,1); @@ -247,7 +266,7 @@ static int open_cred_file(char * file_name) if(length > MOUNT_PASSWD_SIZE) { printf("mount.cifs failed: password in credentials file too long\n"); memset(line_buf,0, 4096); - exit(1); + exit(EX_USAGE); } else { if(mountpassword == NULL) { mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1); @@ -275,7 +294,7 @@ static int open_cred_file(char * file_name) } if(length > DOMAIN_SIZE) { printf("mount.cifs failed: domain in credentials file too long\n"); - exit(1); + exit(EX_USAGE); } else { if(domain_name == NULL) { domain_name = (char *)calloc(DOMAIN_SIZE+1,1); @@ -308,7 +327,7 @@ static int get_password_from_file(int file_descript, char * filename) if (mountpassword == NULL) { printf("malloc failed\n"); - exit(1); + exit(EX_SYSERR); } if(filename != NULL) { @@ -316,7 +335,7 @@ static int get_password_from_file(int file_descript, char * filename) if(file_descript < 0) { printf("mount.cifs failed. %s attempting to open password file %s\n", strerror(errno),filename); - exit(1); + exit(EX_SYSERR); } } /* else file already open and fd provided */ @@ -327,7 +346,7 @@ static int get_password_from_file(int file_descript, char * filename) printf("mount.cifs failed. Error %s reading password file\n",strerror(errno)); if(filename != NULL) close(file_descript); - exit(1); + exit(EX_SYSERR); } else if(rc == 0) { if(mountpassword[0] == 0) { if(verboseflag) @@ -553,7 +572,7 @@ static int parse_options(char ** optionsp, int * filesys_flags) if (!(pw = getpwnam(value))) { printf("bad user name \"%s\"\n", value); - exit(1); + exit(EX_USAGE); } snprintf(user, sizeof(user), "%u", pw->pw_uid); } else { @@ -569,7 +588,7 @@ static int parse_options(char ** optionsp, int * filesys_flags) if (!(gr = getgrnam(value))) { printf("bad group name \"%s\"\n", value); - exit(1); + exit(EX_USAGE); } snprintf(group, sizeof(group), "%u", gr->gr_gid); } else { @@ -664,7 +683,7 @@ static int parse_options(char ** optionsp, int * filesys_flags) out = (char *)realloc(out, out_len + word_len + 2); if (out == NULL) { perror("malloc"); - exit(1); + exit(EX_SYSERR); } if (out_len) { @@ -689,7 +708,7 @@ nocopy: out = (char *)realloc(out, out_len + word_len + 6); if (out == NULL) { perror("malloc"); - exit(1); + exit(EX_SYSERR); } if (out_len) { @@ -705,7 +724,7 @@ nocopy: out = (char *)realloc(out, out_len + 1 + word_len + 6); if (out == NULL) { perror("malloc"); - exit(1); + exit(EX_SYSERR); } if (out_len) { @@ -986,12 +1005,12 @@ static struct option longopts[] = { }; /* convert a string to uppercase. return false if the string - * wasn't ASCII or was a NULL ptr */ + * wasn't ASCII. Return success on a NULL ptr */ static int uppercase_string(char *string) { if (!string) - return 0; + return 1; while (*string) { /* check for unicode */ @@ -1040,7 +1059,7 @@ int main(int argc, char ** argv) thisprogram = argv[0]; } else { mount_cifs_usage(); - exit(1); + exit(EX_USAGE); } if(thisprogram == NULL) @@ -1057,12 +1076,12 @@ int main(int argc, char ** argv) share_name = strndup(argv[1], MAX_UNC_LEN); if (share_name == NULL) { fprintf(stderr, "%s: %s", argv[0], strerror(ENOMEM)); - exit(1); + exit(EX_SYSERR); } mountpoint = argv[2]; } else { mount_cifs_usage(); - exit(1); + exit(EX_USAGE); } /* add sharename in opts string as unc= parm */ @@ -1084,7 +1103,7 @@ int main(int argc, char ** argv) case '?': case 'h': /* help */ mount_cifs_usage (); - exit(1); + exit(EX_USAGE); case 'n': ++nomtab; break; @@ -1138,14 +1157,14 @@ int main(int argc, char ** argv) uid = strtoul(optarg, &ep, 10); if (*ep) { printf("bad uid value \"%s\"\n", optarg); - exit(1); + exit(EX_USAGE); } } else { struct passwd *pw; if (!(pw = getpwnam(optarg))) { printf("bad user name \"%s\"\n", optarg); - exit(1); + exit(EX_USAGE); } uid = pw->pw_uid; endpwent(); @@ -1158,14 +1177,14 @@ int main(int argc, char ** argv) gid = strtoul(optarg, &ep, 10); if (*ep) { printf("bad gid value \"%s\"\n", optarg); - exit(1); + exit(EX_USAGE); } } else { struct group *gr; if (!(gr = getgrnam(optarg))) { printf("bad user name \"%s\"\n", optarg); - exit(1); + exit(EX_USAGE); } gid = gr->gr_gid; endpwent(); @@ -1195,13 +1214,13 @@ int main(int argc, char ** argv) default: printf("unknown mount option %c\n",c); mount_cifs_usage(); - exit(1); + exit(EX_USAGE); } } if((argc < 3) || (dev_name == NULL) || (mountpoint == NULL)) { mount_cifs_usage(); - exit(1); + exit(EX_USAGE); } if (getenv("PASSWD")) { @@ -1218,13 +1237,13 @@ int main(int argc, char ** argv) } if (orgoptions && parse_options(&orgoptions, &flags)) { - rc = -1; + rc = EX_USAGE; goto mount_exit; } ipaddr = parse_server(&share_name); if((ipaddr == NULL) && (got_ip == 0)) { printf("No ip address specified and hostname not found\n"); - rc = -1; + rc = EX_USAGE; goto mount_exit; } @@ -1239,19 +1258,19 @@ int main(int argc, char ** argv) } if(chdir(mountpoint)) { printf("mount error: can not change directory into mount target %s\n",mountpoint); - rc = -1; + rc = EX_USAGE; goto mount_exit; } if(stat (".", &statbuf)) { printf("mount error: mount point %s does not exist\n",mountpoint); - rc = -1; + rc = EX_USAGE; goto mount_exit; } if (S_ISDIR(statbuf.st_mode) == 0) { printf("mount error: mount point %s is not a directory\n",mountpoint); - rc = -1; + rc = EX_USAGE; goto mount_exit; } @@ -1264,7 +1283,7 @@ int main(int argc, char ** argv) #endif } else { printf("mount error: permission denied or not superuser and mount.cifs not installed SUID\n"); - return -1; + exit(EX_USAGE); } } @@ -1279,7 +1298,7 @@ int main(int argc, char ** argv) mountpassword = (char *)calloc(MOUNT_PASSWD_SIZE+1,1); if (!tmp_pass || !mountpassword) { printf("Password not entered, exiting\n"); - return -1; + exit(EX_USAGE); } strlcpy(mountpassword, tmp_pass, MOUNT_PASSWD_SIZE+1); got_password = 1; @@ -1297,7 +1316,7 @@ mount_retry: else { printf("No server share name specified\n"); printf("\nMounting the DFS root for server not implemented yet\n"); - exit(1); + exit(EX_USAGE); } if(user_name) optlen += strlen(user_name) + 6; @@ -1311,7 +1330,7 @@ mount_retry: if(options == NULL) { printf("Could not allocate memory for mount options\n"); - return -1; + exit(EX_SYSERR); } options[0] = 0; @@ -1390,8 +1409,7 @@ mount_retry: printf("mount error %d = %s\n",errno,strerror(errno)); } printf("Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)\n"); - rc = -1; - goto mount_exit; + rc = EX_FAIL; } else { pmntfile = setmntent(MOUNTED, "a+"); if(pmntfile) { @@ -1429,11 +1447,13 @@ mount_retry: rc = addmntent(pmntfile,&mountent); endmntent(pmntfile); SAFE_FREE(mountent.mnt_opts); + if (rc) + rc = EX_FILEIO; } else { - printf("could not update mount table\n"); + printf("could not update mount table\n"); + rc = EX_FILEIO; } } - rc = 0; mount_exit: if(mountpassword) { int len = strlen(mountpassword); @@ -1445,5 +1465,5 @@ mount_exit: SAFE_FREE(orgoptions); SAFE_FREE(resolved_path); SAFE_FREE(share_name); - return rc; + exit(rc); } diff --git a/source3/client/smbspool.c b/source3/client/smbspool.c index 4a173714fe..1910ccd4fe 100644 --- a/source3/client/smbspool.c +++ b/source3/client/smbspool.c @@ -482,7 +482,7 @@ smb_connect(const char *workgroup, /* I - Workgroup */ /* * Get the names and addresses of the client and server... */ - myname = get_myname(talloc_tos()); + myname = talloc_get_myname(talloc_tos()); if (!myname) { return NULL; } |