-/*
+/*
Unix SMB/CIFS implementation.
SMB client
Copyright (C) Andrew Tridgell 1994-1998
Copyright (C) Simo Sorce 2001-2002
Copyright (C) Jelmer Vernooij 2003-2004
Copyright (C) James J Myers 2003 <myersjj@samba.org>
-
+
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 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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, see <http://www.gnu.org/licenses/>.
*/
-/*
+/*
* TODO: remove this ... and don't use talloc_append_string()
*
* NOTE: I'm not changing the code yet, because I assume there're
static unsigned int put_total_time_ms = 0;
/* Unfortunately, there is no way to pass a context to the completion function as an argument */
-static struct smbclient_context *rl_ctx;
+static struct smbclient_context *rl_ctx;
/* totals globals */
static double dir_total;
}
/****************************************************************************
-write to a local file with CR/LF->LF translation if appropriate. return the
+write to a local file with CR/LF->LF translation if appropriate. return the
number taken from the buffer. This may not equal the number written.
****************************************************************************/
static int writefile(int f, const void *_b, int n, bool translation)
b++;
i++;
}
-
+
return(i);
}
/****************************************************************************
- read from a file with LF->CR/LF translation if appropriate. return the
+ read from a file with LF->CR/LF translation if appropriate. return the
number read. read approx n bytes.
****************************************************************************/
static int readfile(void *_b, int n, FILE *f, bool translation)
if (!translation)
return fread(b,1,n,f);
-
+
i = 0;
while (i < (n - 1)) {
if ((c = getc(f)) == EOF) {
break;
}
-
+
if (c == '\n') { /* change all LFs to CR/LF */
b[i++] = '\r';
}
-
+
b[i++] = c;
}
-
+
return(i);
}
-
+
/****************************************************************************
send a message
for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
if (c == '\n')
msg[l++] = '\r';
- msg[l] = c;
+ msg[l] = c;
}
if (!smbcli_message_text(cli->tree, msg, l, grp_id)) {
d_printf("SMBsendtxt failed (%s)\n",smbcli_errstr(cli->tree));
return;
- }
-
+ }
+
total_len += l;
}
if (!smbcli_message_end(cli->tree, grp_id)) {
d_printf("SMBsendend failed (%s)\n",smbcli_errstr(cli->tree));
return;
- }
+ }
}
uint64_t total, avail;
if (NT_STATUS_IS_ERR(smbcli_dskattr(ctx->cli->tree, &bsize, &total, &avail))) {
- d_printf("Error in dskattr: %s\n",smbcli_errstr(ctx->cli->tree));
+ d_printf("Error in dskattr: %s\n",smbcli_errstr(ctx->cli->tree));
return 1;
}
d_printf("\n\t\t%llu blocks of size %u. %llu blocks available\n",
- (unsigned long long)total,
- (unsigned)bsize,
+ (unsigned long long)total,
+ (unsigned)bsize,
(unsigned long long)avail);
return 0;
static int do_cd(struct smbclient_context *ctx, const char *newdir)
{
char *dname;
-
+
/* Save the current directory in case the
new directory is invalid */
if (newdir[0] == '\\')
dname = talloc_append_string(NULL, dname, "\\");
}
dos_clean_name(dname);
-
+
if (NT_STATUS_IS_ERR(smbcli_chkpath(ctx->cli->tree, dname))) {
d_printf("cd %s: %s\n", dname, smbcli_errstr(ctx->cli->tree));
talloc_free(dname);
} else {
ctx->remote_cur_dir = dname;
}
-
+
return 0;
}
{
int rc = 0;
- if (args[1])
+ if (args[1])
rc = do_cd(ctx, args[1]);
else
d_printf("Current directory is %s\n",ctx->remote_cur_dir);
}
-static bool mask_match(struct smbcli_state *c, const char *string,
+static bool mask_match(struct smbcli_state *c, const char *string,
const char *pattern, bool is_case_sensitive)
{
int ret;
{
if (finfo->attrib & FILE_ATTRIBUTE_DIRECTORY) return(true);
- if (ctx->fileselection &&
+ if (ctx->fileselection &&
!mask_match(ctx->cli, finfo->name,ctx->fileselection,false)) {
DEBUG(3,("mask_match %s failed\n", finfo->name));
return false;
DEBUG(3,("archive %s failed\n", finfo->name));
return(false);
}
-
+
return(true);
}
reset_do_list_queue();
do_list_queue_size = 1024;
do_list_queue = malloc_array_p(char, do_list_queue_size);
- if (do_list_queue == 0) {
+ if (do_list_queue == 0) {
d_printf("malloc fail for size %d\n",
(int)do_list_queue_size);
reset_do_list_queue();
do_list_queue_end -= do_list_queue_start;
do_list_queue_start = 0;
}
-
+
}
static void add_to_do_list_queue(const char* entry)
if (do_list_dirs && do_this_one(ctx, f)) {
do_list_fn(ctx, f);
}
- if (do_list_recurse &&
+ if (do_list_recurse &&
!ISDOT(f->name) &&
!ISDOTDOT(f->name)) {
char *mask2;
{
init_do_list_queue();
add_to_do_list_queue(mask);
-
+
while (! do_list_queue_empty())
{
/*
uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
char *mask;
int rc;
-
+
dir_total = 0;
-
+
mask = talloc_strdup(ctx, ctx->remote_cur_dir);
if(mask[strlen(mask)-1]!='\\')
mask = talloc_append_string(ctx, mask,"\\");
-
+
if (args[1]) {
mask = talloc_strdup(ctx, args[1]);
if (mask[0] != '\\')
dos_format(mask);
}
else {
- if (ctx->cli->tree->session->transport->negotiate.protocol <=
- PROTOCOL_LANMAN1) {
+ if (ctx->cli->tree->session->transport->negotiate.protocol <=
+ PROTOCOL_LANMAN1) {
mask = talloc_append_string(ctx, mask, "*.*");
} else {
mask = talloc_append_string(ctx, mask, "*");
uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
int rc;
char *mask;
-
+
dir_total = 0;
-
+
if (args[1]) {
if (args[1][0] == '\\')
mask = talloc_strdup(ctx, args[1]);
get a file from rname to lname
****************************************************************************/
static int do_get(struct smbclient_context *ctx, char *rname, const char *p_lname, bool reget)
-{
+{
int handle = 0, fnum;
bool newhandle = false;
uint8_t *data;
}
- if (NT_STATUS_IS_ERR(smbcli_qfileinfo(ctx->cli->tree, fnum,
+ if (NT_STATUS_IS_ERR(smbcli_qfileinfo(ctx->cli->tree, fnum,
&attr, &size, NULL, NULL, NULL, NULL, NULL)) &&
- NT_STATUS_IS_ERR(smbcli_getattrE(ctx->cli->tree, fnum,
+ NT_STATUS_IS_ERR(smbcli_getattrE(ctx->cli->tree, fnum,
&attr, &size, NULL, NULL, NULL))) {
d_printf("getattrib: %s\n",smbcli_errstr(ctx->cli->tree));
if (newhandle) {
return 1;
}
- DEBUG(2,("getting file %s of size %.0f as %s ",
+ DEBUG(2,("getting file %s of size %.0f as %s ",
rname, (double)size, lname));
- if(!(data = (uint8_t *)malloc(read_size))) {
+ if(!(data = (uint8_t *)malloc(read_size))) {
d_printf("malloc fail for size %d\n", read_size);
smbcli_close(ctx->cli->tree, fnum);
if (newhandle) {
int n = smbcli_read(ctx->cli->tree, fnum, data, nread + start, read_size);
if (n <= 0) break;
-
+
if (writefile(handle,data, n, ctx->translation) != n) {
d_printf("Error writing local file\n");
rc = 1;
break;
}
-
+
nread += n;
}
}
SAFE_FREE(data);
-
+
if (NT_STATUS_IS_ERR(smbcli_close(ctx->cli->tree, fnum))) {
d_printf("Error %s closing remote file\n",smbcli_errstr(ctx->cli->tree));
rc = 1;
{
struct timeval tp_end;
int this_time;
-
+
GetTimeOfDay(&tp_end);
- this_time =
+ this_time =
(tp_end.tv_sec - tp_start.tv_sec)*1000 +
(tp_end.tv_usec - tp_start.tv_usec)/1000;
get_total_time_ms += this_time;
get_total_size += nread;
-
+
DEBUG(2,("(%3.1f kb/s) (average %3.1f kb/s)\n",
nread / (1.024*this_time + 1.0e-4),
get_total_size / (1.024*get_total_time_ms)));
}
-
+
return rc;
}
rname = talloc_asprintf(ctx, "%s\\%s", ctx->remote_cur_dir, args[1]);
- if (args[2])
+ if (args[2])
lname = args[2];
- else
+ else
lname = args[1];
-
+
dos_clean_name(rname);
-
+
return do_get(ctx, rname, lname, false);
}
} else {
l_fname = talloc_strdup(ctx, finfo->name);
}
-
+
string_replace(l_fname, '\\', '/');
if (!directory_exist(l_fname) &&
d_printf("failed to create directory %s\n", l_fname);
return;
}
-
+
if (chdir(l_fname) != 0) {
d_printf("failed to chdir to directory %s\n", l_fname);
return;
}
mget_mask = talloc_asprintf(ctx, "%s*", ctx->remote_cur_dir);
-
+
do_list(ctx, mget_mask, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY,do_mget,false, true);
ret = chdir("..");
if (ret == -1) {
return 1;
}
unlink(lname);
-
+
return rc;
}
if (ctx->recurse)
attribute |= FILE_ATTRIBUTE_DIRECTORY;
-
+
for (i = 1; args[i]; i++) {
mget_mask = talloc_strdup(ctx, ctx->remote_cur_dir);
if(mget_mask[strlen(mget_mask)-1]!='\\')
mget_mask = talloc_append_string(ctx, mget_mask, "\\");
-
+
mget_mask = talloc_strdup(ctx, args[i]);
if (mget_mask[0] != '\\')
mget_mask = talloc_append_string(ctx, mget_mask, "\\");
do_list(ctx, mget_mask, attribute,do_mget,false,true);
talloc_free(mget_mask);
}
-
+
return 0;
}
static int cmd_mkdir(struct smbclient_context *ctx, const char **args)
{
char *mask, *p;
-
+
if (!args[1]) {
if (!ctx->recurse)
d_printf("mkdir <dirname>\n");
trim_string(mask,".",NULL);
for (p = strtok(mask,"/\\"); p; p = strtok(p, "/\\")) {
char *parent = talloc_strndup(ctx, mask, PTR_DIFF(p, mask));
-
- if (NT_STATUS_IS_ERR(smbcli_chkpath(ctx->cli->tree, parent))) {
+
+ if (NT_STATUS_IS_ERR(smbcli_chkpath(ctx->cli->tree, parent))) {
do_mkdir(ctx, parent);
}
talloc_free(parent);
- }
+ }
} else {
do_mkdir(ctx, mask);
}
-
+
return 0;
}
const char *p;
char *altname;
char *name;
-
+
if (!args[1]) {
d_printf("altname <file>\n");
return 1;
uint8_t *buf = NULL;
int maxwrite = ctx->io_bufsize;
int rc = 0;
-
+
struct timeval tp_start;
GetTimeOfDay(&tp_start);
}
}
} else {
- fnum = smbcli_open(ctx->cli->tree, rname, O_RDWR|O_CREAT|O_TRUNC,
+ fnum = smbcli_open(ctx->cli->tree, rname, O_RDWR|O_CREAT|O_TRUNC,
DENY_NONE);
}
-
+
if (fnum == -1) {
d_printf("%s opening remote file %s\n",smbcli_errstr(ctx->cli->tree),rname);
return 1;
return 1;
}
-
+
DEBUG(1,("putting file %s as %s ",lname,
rname));
-
+
buf = (uint8_t *)malloc(maxwrite);
if (!buf) {
d_printf("ERROR: Not enough memory!\n");
d_printf("Error writing file: %s\n", smbcli_errstr(ctx->cli->tree));
rc = 1;
break;
- }
+ }
nread += n;
}
return 1;
}
-
+
if (f != stdin) {
fclose(f);
}
{
struct timeval tp_end;
int this_time;
-
+
GetTimeOfDay(&tp_end);
- this_time =
+ this_time =
(tp_end.tv_sec - tp_start.tv_sec)*1000 +
(tp_end.tv_usec - tp_start.tv_usec)/1000;
put_total_time_ms += this_time;
put_total_size += nread;
-
+
DEBUG(1,("(%3.1f kb/s) (average %3.1f kb/s)\n",
nread / (1.024*this_time + 1.0e-4),
put_total_size / (1.024*put_total_time_ms)));
talloc_free(ctx);
exit(0);
}
-
+
return rc;
}
-
+
/****************************************************************************
put a file
{
char *lname;
char *rname;
-
+
if (!args[1]) {
d_printf("put <filename> [<remotename>]\n");
return 1;
}
lname = talloc_strdup(ctx, args[1]);
-
+
if (args[2]) {
if (args[2][0]=='\\')
rname = talloc_strdup(ctx, args[2]);
} else {
rname = talloc_asprintf(ctx, "%s\\%s", ctx->remote_cur_dir, lname);
}
-
+
dos_clean_name(rname);
/* allow '-' to represent stdin
static void free_file_list (struct file_list * list)
{
struct file_list *tmp;
-
+
while (list)
{
tmp = list;
}
list = list->next;
}
-
+
return(false);
}
if (!p)
return(NULL);
-
+
ptr = (struct dirent *)readdir(p);
if (!ptr)
return(NULL);
Recursive file matching function act as find
match must be always set to true when calling this function
****************************************************************************/
-static int file_find(struct smbclient_context *ctx, struct file_list **list, const char *directory,
+static int file_find(struct smbclient_context *ctx, struct file_list **list, const char *directory,
const char *expression, bool match)
{
DIR *dir;
dir = opendir(directory);
if (!dir) return -1;
-
+
while ((dname = readdirname(dir))) {
if (ISDOT(dname) || ISDOTDOT(dname)) {
continue;
}
-
+
if (asprintf(&path, "%s/%s", directory, dname) <= 0) {
continue;
}
} else {
d_printf("file_find: cannot stat file %s\n", path);
}
-
+
if (ret == -1) {
SAFE_FREE(path);
closedir(dir);
static int cmd_mput(struct smbclient_context *ctx, const char **args)
{
int i;
-
+
for (i = 1; args[i]; i++) {
int ret;
struct file_list *temp_list;
char *quest, *lname, *rname;
printf("%s\n", args[i]);
-
+
file_list = NULL;
ret = file_find(ctx, &file_list, ".", args[i], true);
free_file_list(file_list);
continue;
}
-
+
quest = NULL;
lname = NULL;
rname = NULL;
-
- for (temp_list = file_list; temp_list;
+
+ for (temp_list = file_list; temp_list;
temp_list = temp_list->next) {
SAFE_FREE(lname);
if (asprintf(&lname, "%s/", temp_list->file_path) <= 0)
continue;
trim_string(lname, "./", "/");
-
+
/* check if it's a directory */
if (temp_list->isdir) {
/* if (!recurse) continue; */
-
+
SAFE_FREE(quest);
if (asprintf(&quest, "Put directory %s? ", lname) < 0) break;
if (ctx->prompt && !yesno(quest)) { /* No */
/* Skip the directory */
lname[strlen(lname)-1] = '/';
if (!seek_list(temp_list, lname))
- break;
+ break;
} else { /* Yes */
SAFE_FREE(rname);
if(asprintf(&rname, "%s%s", ctx->remote_cur_dir, lname) < 0) break;
dos_format(rname);
- if (NT_STATUS_IS_ERR(smbcli_chkpath(ctx->cli->tree, rname)) &&
+ if (NT_STATUS_IS_ERR(smbcli_chkpath(ctx->cli->tree, rname)) &&
NT_STATUS_IS_ERR(do_mkdir(ctx, rname))) {
DEBUG (0, ("Unable to make dir, skipping...\n"));
/* Skip the directory */
if (asprintf(&quest,"Put file %s? ", lname) < 0) break;
if (ctx->prompt && !yesno(quest)) /* No */
continue;
-
+
/* Yes */
SAFE_FREE(rname);
if (asprintf(&rname, "%s%s", ctx->remote_cur_dir, lname) < 0) break;
static int cmd_rewrite(struct smbclient_context *ctx, const char **args)
{
d_printf("REWRITE: command not implemented (FIXME!)\n");
-
+
return 0;
}
static int cmd_del(struct smbclient_context *ctx, const char **args)
{
char *mask;
-
+
if (!args[1]) {
d_printf("del <filename>\n");
return 1;
if (NT_STATUS_IS_ERR(smbcli_unlink(ctx->cli->tree, mask))) {
d_printf("%s deleting remote file %s\n",smbcli_errstr(ctx->cli->tree),mask);
}
-
+
return 0;
}
}
dname = talloc_asprintf(ctx, "%s%s", ctx->remote_cur_dir, args[1]);
-
+
ret = smbcli_deltree(ctx->cli->tree, dname);
if (ret == -1) {
}
printf("Deleted %d files in %s\n", ret, dname);
-
+
return 0;
}
union smb_fsinfo fsinfo;
NTSTATUS status;
fsinfo_level_t *fsinfo_level;
-
+
if (!args[1]) {
d_printf("fsinfo <level>, where level is one of following:\n");
fsinfo_level = fsinfo_levels;
}
return 1;
}
-
+
fsinfo_level = fsinfo_levels;
while(fsinfo_level->level_name && !strequal(args[1],fsinfo_level->level_name)) {
fsinfo_level++;
}
-
+
if (!fsinfo_level->level_name) {
d_printf("wrong level name!\n");
return 1;
}
-
+
fsinfo.generic.level = fsinfo_level->level;
status = smb_raw_fsinfo(ctx->cli->tree, ctx, &fsinfo);
if (!NT_STATUS_IS_OK(status)) {
d_printf("fsinfo-level-%s:\n", fsinfo_level->level_name);
switch(fsinfo.generic.level) {
case RAW_QFS_DSKATTR:
- d_printf("\tunits_total: %hu\n",
+ d_printf("\tunits_total: %hu\n",
(unsigned short) fsinfo.dskattr.out.units_total);
- d_printf("\tblocks_per_unit: %hu\n",
+ d_printf("\tblocks_per_unit: %hu\n",
(unsigned short) fsinfo.dskattr.out.blocks_per_unit);
- d_printf("\tblocks_size: %hu\n",
+ d_printf("\tblocks_size: %hu\n",
(unsigned short) fsinfo.dskattr.out.block_size);
- d_printf("\tunits_free: %hu\n",
+ d_printf("\tunits_free: %hu\n",
(unsigned short) fsinfo.dskattr.out.units_free);
break;
case RAW_QFS_ALLOCATION:
- d_printf("\tfs_id: %lu\n",
+ d_printf("\tfs_id: %lu\n",
(unsigned long) fsinfo.allocation.out.fs_id);
- d_printf("\tsectors_per_unit: %lu\n",
+ d_printf("\tsectors_per_unit: %lu\n",
(unsigned long) fsinfo.allocation.out.sectors_per_unit);
- d_printf("\ttotal_alloc_units: %lu\n",
+ d_printf("\ttotal_alloc_units: %lu\n",
(unsigned long) fsinfo.allocation.out.total_alloc_units);
- d_printf("\tavail_alloc_units: %lu\n",
+ d_printf("\tavail_alloc_units: %lu\n",
(unsigned long) fsinfo.allocation.out.avail_alloc_units);
- d_printf("\tbytes_per_sector: %hu\n",
+ d_printf("\tbytes_per_sector: %hu\n",
(unsigned short) fsinfo.allocation.out.bytes_per_sector);
break;
case RAW_QFS_VOLUME:
- d_printf("\tserial_number: %lu\n",
+ d_printf("\tserial_number: %lu\n",
(unsigned long) fsinfo.volume.out.serial_number);
d_printf("\tvolume_name: %s\n", fsinfo.volume.out.volume_name.s);
break;
case RAW_QFS_VOLUME_INFORMATION:
d_printf("\tcreate_time: %s\n",
nt_time_string(ctx,fsinfo.volume_info.out.create_time));
- d_printf("\tserial_number: %lu\n",
+ d_printf("\tserial_number: %lu\n",
(unsigned long) fsinfo.volume_info.out.serial_number);
d_printf("\tvolume_name: %s\n", fsinfo.volume_info.out.volume_name.s);
break;
case RAW_QFS_SIZE_INFO:
case RAW_QFS_SIZE_INFORMATION:
- d_printf("\ttotal_alloc_units: %llu\n",
+ d_printf("\ttotal_alloc_units: %llu\n",
(unsigned long long) fsinfo.size_info.out.total_alloc_units);
- d_printf("\tavail_alloc_units: %llu\n",
+ d_printf("\tavail_alloc_units: %llu\n",
(unsigned long long) fsinfo.size_info.out.avail_alloc_units);
- d_printf("\tsectors_per_unit: %lu\n",
+ d_printf("\tsectors_per_unit: %lu\n",
(unsigned long) fsinfo.size_info.out.sectors_per_unit);
- d_printf("\tbytes_per_sector: %lu\n",
+ d_printf("\tbytes_per_sector: %lu\n",
(unsigned long) fsinfo.size_info.out.bytes_per_sector);
break;
case RAW_QFS_DEVICE_INFO:
case RAW_QFS_DEVICE_INFORMATION:
- d_printf("\tdevice_type: %lu\n",
+ d_printf("\tdevice_type: %lu\n",
(unsigned long) fsinfo.device_info.out.device_type);
- d_printf("\tcharacteristics: 0x%lx\n",
+ d_printf("\tcharacteristics: 0x%lx\n",
(unsigned long) fsinfo.device_info.out.characteristics);
break;
case RAW_QFS_ATTRIBUTE_INFORMATION:
case RAW_QFS_ATTRIBUTE_INFO:
- d_printf("\tfs_attr: 0x%lx\n",
+ d_printf("\tfs_attr: 0x%lx\n",
(unsigned long) fsinfo.attribute_info.out.fs_attr);
- d_printf("\tmax_file_component_length: %lu\n",
+ d_printf("\tmax_file_component_length: %lu\n",
(unsigned long) fsinfo.attribute_info.out.max_file_component_length);
d_printf("\tfs_type: %s\n", fsinfo.attribute_info.out.fs_type.s);
break;
case RAW_QFS_UNIX_INFO:
- d_printf("\tmajor_version: %hu\n",
+ d_printf("\tmajor_version: %hu\n",
(unsigned short) fsinfo.unix_info.out.major_version);
- d_printf("\tminor_version: %hu\n",
+ d_printf("\tminor_version: %hu\n",
(unsigned short) fsinfo.unix_info.out.minor_version);
- d_printf("\tcapability: 0x%llx\n",
+ d_printf("\tcapability: 0x%llx\n",
(unsigned long long) fsinfo.unix_info.out.capability);
break;
case RAW_QFS_QUOTA_INFORMATION:
- d_printf("\tunknown[3]: [%llu,%llu,%llu]\n",
+ d_printf("\tunknown[3]: [%llu,%llu,%llu]\n",
(unsigned long long) fsinfo.quota_information.out.unknown[0],
(unsigned long long) fsinfo.quota_information.out.unknown[1],
(unsigned long long) fsinfo.quota_information.out.unknown[2]);
- d_printf("\tquota_soft: %llu\n",
+ d_printf("\tquota_soft: %llu\n",
(unsigned long long) fsinfo.quota_information.out.quota_soft);
- d_printf("\tquota_hard: %llu\n",
+ d_printf("\tquota_hard: %llu\n",
(unsigned long long) fsinfo.quota_information.out.quota_hard);
- d_printf("\tquota_flags: 0x%llx\n",
+ d_printf("\tquota_flags: 0x%llx\n",
(unsigned long long) fsinfo.quota_information.out.quota_flags);
break;
case RAW_QFS_FULL_SIZE_INFORMATION:
- d_printf("\ttotal_alloc_units: %llu\n",
+ d_printf("\ttotal_alloc_units: %llu\n",
(unsigned long long) fsinfo.full_size_information.out.total_alloc_units);
- d_printf("\tcall_avail_alloc_units: %llu\n",
+ d_printf("\tcall_avail_alloc_units: %llu\n",
(unsigned long long) fsinfo.full_size_information.out.call_avail_alloc_units);
- d_printf("\tactual_avail_alloc_units: %llu\n",
+ d_printf("\tactual_avail_alloc_units: %llu\n",
(unsigned long long) fsinfo.full_size_information.out.actual_avail_alloc_units);
- d_printf("\tsectors_per_unit: %lu\n",
+ d_printf("\tsectors_per_unit: %lu\n",
(unsigned long) fsinfo.full_size_information.out.sectors_per_unit);
- d_printf("\tbytes_per_sector: %lu\n",
+ d_printf("\tbytes_per_sector: %lu\n",
(unsigned long) fsinfo.full_size_information.out.bytes_per_sector);
break;
case RAW_QFS_OBJECTID_INFORMATION:
- d_printf("\tGUID: %s\n",
+ d_printf("\tGUID: %s\n",
GUID_string(ctx,&fsinfo.objectid_information.out.guid));
- d_printf("\tunknown[6]: [%llu,%llu,%llu,%llu,%llu,%llu]\n",
+ d_printf("\tunknown[6]: [%llu,%llu,%llu,%llu,%llu,%llu]\n",
(unsigned long long) fsinfo.objectid_information.out.unknown[0],
(unsigned long long) fsinfo.objectid_information.out.unknown[1],
(unsigned long long) fsinfo.objectid_information.out.unknown[2],
d_printf("\twrong level returned\n");
break;
}
-
+
return 0;
}
finfo.generic.level = RAW_FILEINFO_INTERNAL_INFORMATION;
status = smb_raw_pathinfo(ctx->cli->tree, ctx, &finfo);
if (NT_STATUS_IS_OK(status)) {
- d_printf("\tfile_id %.0f\n",
+ d_printf("\tfile_id %.0f\n",
(double)finfo.internal_information.out.file_id);
}
int i;
for (i=0;i<finfo.stream_info.out.num_streams;i++) {
d_printf("\tstream %d:\n", i);
- d_printf("\t\tsize %ld\n",
+ d_printf("\t\tsize %ld\n",
(long)finfo.stream_info.out.streams[i].size);
- d_printf("\t\talloc size %ld\n",
+ d_printf("\t\talloc size %ld\n",
(long)finfo.stream_info.out.streams[i].alloc_size);
d_printf("\t\tname %s\n", finfo.stream_info.out.streams[i].stream_name.s);
}
- }
+ }
/* dev/inode if available */
finfo.generic.level = RAW_FILEINFO_COMPRESSION_INFORMATION;
for (i=0;i<info.out.num_names;i++) {
d_printf("\t%s\n", info.out.names[i]);
finfo.generic.level = RAW_FILEINFO_ALL_INFO;
- finfo.generic.in.file.path = talloc_asprintf(ctx, "%s%s",
- info.out.names[i], fname);
+ finfo.generic.in.file.path = talloc_asprintf(ctx, "%s%s",
+ info.out.names[i], fname);
status = smb_raw_pathinfo(ctx->cli->tree, ctx, &finfo);
if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND) ||
NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
continue;
}
if (!NT_STATUS_IS_OK(status)) {
- d_printf("%s - %s\n", finfo.generic.in.file.path,
+ d_printf("%s - %s\n", finfo.generic.in.file.path,
nt_errstr(status));
return 1;
}
-
+
d_printf("\t\tcreate_time: %s\n", nt_time_string(ctx, finfo.all_info.out.create_time));
d_printf("\t\twrite_time: %s\n", nt_time_string(ctx, finfo.all_info.out.write_time));
d_printf("\t\tchange_time: %s\n", nt_time_string(ctx, finfo.all_info.out.change_time));
}
}
}
-
+
return 0;
}
finfo.generic.level = RAW_FILEINFO_ALL_EAS;
finfo.generic.in.file.path = fname;
status = smb_raw_pathinfo(ctx->cli->tree, ctx, &finfo);
-
+
if (!NT_STATUS_IS_OK(status)) {
d_printf("RAW_FILEINFO_ALL_EAS - %s\n", nt_errstr(status));
return 1;
(int)finfo.all_eas.out.eas[i].value.length,
finfo.all_eas.out.eas[i].name.s);
fflush(stdout);
- dump_data(0,
+ dump_data(0,
finfo.all_eas.out.eas[i].value.data,
finfo.all_eas.out.eas[i].value.length);
}
}
fname = talloc_asprintf(ctx, "%s%s", ctx->remote_cur_dir, args[1]);
- fnum = smbcli_nt_create_full(ctx->cli->tree, fname, 0,
+ fnum = smbcli_nt_create_full(ctx->cli->tree, fname, 0,
SEC_STD_READ_CONTROL,
0,
NTCREATEX_SHARE_ACCESS_DELETE|
NTCREATEX_SHARE_ACCESS_READ|
- NTCREATEX_SHARE_ACCESS_WRITE,
+ NTCREATEX_SHARE_ACCESS_WRITE,
NTCREATEX_DISP_OPEN,
0, 0);
if (fnum == -1) {
ZERO_STRUCT(rights);
for (i = 2; args[i]; i++) {
- rights.names = talloc_realloc(ctx, rights.names,
+ rights.names = talloc_realloc(ctx, rights.names,
struct lsa_StringLarge, rights.count+1);
rights.names[rights.count].string = talloc_strdup(ctx, args[i]);
rights.count++;
ZERO_STRUCT(rights);
for (i = 2; args[i]; i++) {
- rights.names = talloc_realloc(ctx, rights.names,
+ rights.names = talloc_realloc(ctx, rights.names,
struct lsa_StringLarge, rights.count+1);
rights.names[rights.count].string = talloc_strdup(ctx, args[i]);
rights.count++;
static int cmd_rmdir(struct smbclient_context *ctx, const char **args)
{
char *mask;
-
+
if (!args[1]) {
d_printf("rmdir <dirname>\n");
return 1;
d_printf("%s removing remote directory file %s\n",
smbcli_errstr(ctx->cli->tree),mask);
}
-
+
return 0;
}
static int cmd_link(struct smbclient_context *ctx, const char **args)
{
char *src,*dest;
-
+
if (!(ctx->cli->transport->negotiate.capabilities & CAP_UNIX)) {
d_printf("Server doesn't support UNIX CIFS calls.\n");
return 1;
}
-
+
if (!args[1] || !args[2]) {
d_printf("link <src> <dest>\n");
return 1;
if (NT_STATUS_IS_ERR(smbcli_unix_hardlink(ctx->cli->tree, src, dest))) {
d_printf("%s linking files (%s -> %s)\n", smbcli_errstr(ctx->cli->tree), src, dest);
return 1;
- }
+ }
return 0;
}
static int cmd_symlink(struct smbclient_context *ctx, const char **args)
{
char *src,*dest;
-
+
if (!(ctx->cli->transport->negotiate.capabilities & CAP_UNIX)) {
d_printf("Server doesn't support UNIX CIFS calls.\n");
return 1;
d_printf("%s symlinking files (%s -> %s)\n",
smbcli_errstr(ctx->cli->tree), src, dest);
return 1;
- }
+ }
return 0;
}
{
char *src;
mode_t mode;
-
+
if (!(ctx->cli->transport->negotiate.capabilities & CAP_UNIX)) {
d_printf("Server doesn't support UNIX CIFS calls.\n");
return 1;
}
src = talloc_asprintf(ctx, "%s%s", ctx->remote_cur_dir, args[2]);
-
+
mode = (mode_t)strtol(args[1], NULL, 8);
if (NT_STATUS_IS_ERR(smbcli_unix_chmod(ctx->cli->tree, src, mode))) {
d_printf("%s chmod file %s 0%o\n",
smbcli_errstr(ctx->cli->tree), src, (unsigned)mode);
return 1;
- }
+ }
return 0;
}
char *src;
uid_t uid;
gid_t gid;
-
+
if (!(ctx->cli->transport->negotiate.capabilities & CAP_UNIX)) {
d_printf("Server doesn't support UNIX CIFS calls.\n");
return 1;
d_printf("%s chown file %s uid=%d, gid=%d\n",
smbcli_errstr(ctx->cli->tree), src, (int)uid, (int)gid);
return 1;
- }
+ }
return 0;
}
static int cmd_rename(struct smbclient_context *ctx, const char **args)
{
char *src,*dest;
-
+
if (!args[1] || !args[2]) {
d_printf("rename <src> <dest>\n");
return 1;
d_printf("%s renaming files\n",smbcli_errstr(ctx->cli->tree));
return 1;
}
-
+
return 0;
}
{
ctx->prompt = !ctx->prompt;
DEBUG(2,("prompting is now %s\n",ctx->prompt?"on":"off"));
-
+
return 1;
}
{
if (args[1]) {
if (strequal(args[1],"text")) {
- ctx->printmode = 0;
+ ctx->printmode = 0;
} else {
if (strequal(args[1],"graphics"))
ctx->printmode = 1;
switch(ctx->printmode)
{
- case 0:
+ case 0:
DEBUG(2,("the printmode is now text\n"));
break;
- case 1:
+ case 1:
DEBUG(2,("the printmode is now graphics\n"));
break;
- default:
+ default:
DEBUG(2,("the printmode is now %d\n", ctx->printmode));
break;
}
-
+
return 0;
}
static int cmd_lcd(struct smbclient_context *ctx, const char **args)
{
char d[PATH_MAX];
-
+
if (args[1]) {
int ret;
int i;
hlist = history_list();
-
+
for (i = 0; hlist && hlist[i]; i++) {
DEBUG(0, ("%d: %s\n", i, hlist[i]->line));
}
}
remote_name = talloc_asprintf(ctx, "%s\\%s", ctx->remote_cur_dir, args[1]);
dos_clean_name(remote_name);
-
- if (args[2])
+
+ if (args[2])
local_name = talloc_strdup(ctx, args[2]);
else
local_name = talloc_strdup(ctx, args[1]);
-
+
return do_get(ctx, remote_name, local_name, true);
}
{
char *local_name;
char *remote_name;
-
+
if (!args[1]) {
d_printf("reput <filename>\n");
return 1;
}
local_name = talloc_asprintf(ctx, "%s\\%s", ctx->remote_cur_dir, args[1]);
-
+
if (!file_exist(local_name)) {
d_printf("%s does not exist\n", local_name);
return 1;
}
- if (args[2])
+ if (args[2])
remote_name = talloc_strdup(ctx, args[2]);
else
remote_name = talloc_strdup(ctx, args[1]);
-
+
dos_clean_name(remote_name);
return do_put(ctx, remote_name, local_name, true);
static const char *share_type_str(uint32_t type)
{
switch (type & 0xF) {
- case STYPE_DISKTREE:
+ case STYPE_DISKTREE:
return "Disk";
- case STYPE_PRINTQ:
+ case STYPE_PRINTQ:
return "Printer";
- case STYPE_DEVICE:
+ case STYPE_DEVICE:
return "Device";
- case STYPE_IPC:
+ case STYPE_IPC:
return "IPC";
default:
return "Unknown";
for (i=0;i<ctr1->count;i++) {
struct srvsvc_NetShareInfo1 *info = ctr1->array+i;
- printf("\t%-15s %-10.10s %s\n",
- info->name,
- share_type_str(info->type),
+ printf("\t%-15s %-10.10s %s\n",
+ info->name,
+ share_type_str(info->type),
info->comment);
}
}
binding = talloc_asprintf(mem_ctx, "ncacn_np:%s", query_host);
- status = dcerpc_pipe_connect(mem_ctx, &p, binding,
+ status = dcerpc_pipe_connect(mem_ctx, &p, binding,
&ndr_table_srvsvc,
creds,
ev_ctx,
lp_ctx);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("Failed to connect to %s - %s\n",
+ d_printf("Failed to connect to %s - %s\n",
binding, nt_errstr(status));
talloc_free(mem_ctx);
return false;
ZERO_STRUCT(ctr1);
status = dcerpc_srvsvc_NetShareEnumAll_r(p->binding_handle, mem_ctx, &r);
- if (NT_STATUS_IS_OK(status) &&
+ if (NT_STATUS_IS_OK(status) &&
(W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA) ||
W_ERROR_IS_OK(r.out.result)) &&
r.out.info_ctr->ctr.ctr1) {
talloc_free(mem_ctx);
if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
- d_printf("Failed NetShareEnumAll %s - %s/%s\n",
+ d_printf("Failed NetShareEnumAll %s - %s/%s\n",
binding, nt_errstr(status), win_errstr(r.out.result));
return false;
}
int (*fn)(struct smbclient_context *ctx, const char **args);
const char *description;
char compl_args[2]; /* Completion argument info */
-} commands[] =
+} commands[] =
{
{"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
{"addprivileges",cmd_addprivileges,"<sid|name> <privilege...> add privileges for a user",{COMPL_NONE,COMPL_NONE}},
{"lcd",cmd_lcd,"[directory] change/report the local current working directory",{COMPL_LOCAL,COMPL_NONE}},
{"link",cmd_link,"<src> <dest> create a UNIX hard link",{COMPL_REMOTE,COMPL_REMOTE}},
{"lookup",cmd_lookup,"<sid|name> show SID for name or name for SID",{COMPL_NONE,COMPL_NONE}},
- {"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
+ {"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
{"ls",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
{"mask",cmd_select,"<mask> mask all filenames against this",{COMPL_REMOTE,COMPL_NONE}},
{"md",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
{"mget",cmd_mget,"<mask> get all the matching files",{COMPL_REMOTE,COMPL_NONE}},
{"mkdir",cmd_mkdir,"<directory> make a directory",{COMPL_NONE,COMPL_NONE}},
- {"more",cmd_more,"<remote name> view a remote file with your pager",{COMPL_REMOTE,COMPL_NONE}},
+ {"more",cmd_more,"<remote name> view a remote file with your pager",{COMPL_REMOTE,COMPL_NONE}},
{"mput",cmd_mput,"<mask> put all matching files",{COMPL_REMOTE,COMPL_NONE}},
{"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}},
{"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}},
{"privileges",cmd_privileges,"<user> show privileges for a user",{COMPL_NONE,COMPL_NONE}},
{"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}},
{"printmode",cmd_printmode,"<graphics or text> set the print mode",{COMPL_NONE,COMPL_NONE}},
- {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
+ {"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
{"put",cmd_put,"<local name> [remote name] put a file",{COMPL_LOCAL,COMPL_REMOTE}},
{"pwd",cmd_pwd,"show current remote directory (same as 'cd' with no args)",{COMPL_NONE,COMPL_NONE}},
{"q",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
{"queue",cmd_rewrite,"show the print queue",{COMPL_NONE,COMPL_NONE}},
{"quit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
{"rd",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
- {"recurse",cmd_recurse,"toggle directory recursion for mget and mput",{COMPL_NONE,COMPL_NONE}},
+ {"recurse",cmd_recurse,"toggle directory recursion for mget and mput",{COMPL_NONE,COMPL_NONE}},
{"reget",cmd_reget,"<remote name> [local name] get a file restarting at end of local file",{COMPL_REMOTE,COMPL_LOCAL}},
{"rename",cmd_rename,"<src> <dest> rename some files",{COMPL_REMOTE,COMPL_REMOTE}},
{"reput",cmd_reput,"<local name> [remote name] put a file restarting at end of remote file",{COMPL_LOCAL,COMPL_REMOTE}},
{"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
{"symlink",cmd_symlink,"<src> <dest> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
{"translate",cmd_translate,"toggle text translation for printing",{COMPL_NONE,COMPL_NONE}},
-
+
/* Yes, this must be here, see crh's comment above. */
{"!",NULL,"run a shell command on the local system",{COMPL_NONE,COMPL_NONE}},
{NULL,NULL,NULL,{COMPL_NONE,COMPL_NONE}}
/*******************************************************************
- lookup a command string in the list of commands, including
+ lookup a command string in the list of commands, including
abbreviations
******************************************************************/
static int process_tok(const char *tok)
}
i++;
}
-
+
if (matches == 0)
return(-1);
else if (matches == 1)
static int cmd_help(struct smbclient_context *ctx, const char **args)
{
int i=0,j;
-
+
if (args[1]) {
if ((i = process_tok(args[1])) >= 0)
d_printf("HELP %s:\n\t%s\n\n",commands[i].name,commands[i].description);
talloc_free(lines);
return rc;
-}
+}
#define MAX_COMPLETIONS 100
tmp = talloc_asprintf(NULL, "%s/%s", info->dirmask, f->name);
else
tmp = talloc_strdup(NULL, f->name);
-
+
if (f->attrib & FILE_ATTRIBUTE_DIRECTORY)
tmp = talloc_append_string(NULL, tmp, "/");
info->matches[info->count] = tmp;
goto cleanup;
}
- if (smbcli_list(rl_ctx->cli->tree, dirmask,
- FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
+ if (smbcli_list(rl_ctx->cli->tree, dirmask,
+ FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
completion_remote_filter, &info) < 0)
goto cleanup;
buf = smb_readline_get_line_buffer();
if (buf == NULL)
return NULL;
-
+
sp = strchr(buf, ' ');
if (sp == NULL)
return NULL;
-
+
for (i = 0; commands[i].name; i++)
if ((strncmp(commands[i].name, text, sp - buf) == 0) && (commands[i].name[sp - buf] == 0))
break;
}
-/*****************************************************
+/*****************************************************
return a connection to a server
*******************************************************/
-static bool do_connect(struct smbclient_context *ctx,
+static bool do_connect(struct smbclient_context *ctx,
struct tevent_context *ev_ctx,
struct resolve_context *resolve_ctx,
- const char *specified_server, const char **ports,
- const char *specified_share,
+ const char *specified_server, const char **ports,
+ const char *specified_share,
const char *socket_options,
- struct cli_credentials *cred,
+ struct cli_credentials *cred,
struct smbcli_options *options,
struct smbcli_session_options *session_options,
struct gensec_settings *gensec_settings)
}
status = smbcli_full_connection(ctx, &ctx->cli, server, ports,
- share, NULL,
+ share, NULL,
socket_options,
- cred, resolve_ctx,
+ cred, resolve_ctx,
ev_ctx, options, session_options,
gensec_settings);
if (!NT_STATUS_IS_OK(status)) {
- d_printf("Connection to \\\\%s\\%s failed - %s\n",
+ d_printf("Connection to \\\\%s\\%s failed - %s\n",
server, share, nt_errstr(status));
talloc_free(ctx);
return false;
POPT_COMMON_VERSION
POPT_TABLEEND
};
-
+
mem_ctx = talloc_init("client.c/main");
if (!mem_ctx) {
d_printf("\nclient.c: Not enough memory\n");
* (Messenger Service). Make sure we default
* to port 139 instead of port 445. srl,crh
*/
- name_type = 0x03;
+ name_type = 0x03;
desthost = strdup(poptGetOptArg(pc));
if( 0 == port ) port = 139;
message = true;
gensec_init();
if(poptPeekArg(pc)) {
- char *s = strdup(poptGetArg(pc));
+ char *s = strdup(poptGetArg(pc));
/* Convert any '/' characters in the service name to '\' characters */
string_replace(s, '/','\\');
creds = samba_cmdline_get_creds();
lp_ctx = samba_cmdline_get_lp_ctx();
- if (poptPeekArg(pc)) {
+ if (poptPeekArg(pc)) {
cli_credentials_set_password(creds,
poptGetArg(pc), CRED_SPECIFIED);
}
p++;
sscanf(p, "%x", &name_type);
}
-
+
if (query_host) {
rc = do_host_query(lp_ctx, ev_ctx, query_host,
lpcfg_workgroup(lp_ctx));
lpcfg_smb_ports(lp_ctx), dest_ip,
name_type, ev_ctx,
lpcfg_resolve_context(lp_ctx),
- &smb_options,
+ &smb_options,
lpcfg_socket_options(lp_ctx));
return rc;
}
-
+
if (!do_connect(ctx, ev_ctx, lpcfg_resolve_context(lp_ctx),
desthost, lpcfg_smb_ports(lp_ctx), service,
lpcfg_socket_options(lp_ctx),
do_cd(ctx, base_directory);
free(base_directory);
}
-
+
if (cmdstr) {
rc = process_command_string(ctx, cmdstr);
} else {