This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/*
+ * TODO: remove this ... and don't use talloc_append_string()
+ *
+ * NOTE: I'm not changing the code yet, because I assume there're
+ * some bugs in the existing code and I'm not sure how to fix
+ * them correctly.
+ */
+#define TALLOC_DEPRECATED 1
+
#include "includes.h"
#include "version.h"
#include "libcli/libcli.h"
#include "libcli/util/clilsa.h"
#include "system/dir.h"
#include "system/filesys.h"
-#include "dlinklist.h"
+#include "lib/util/dlinklist.h"
#include "system/readline.h"
+#include "auth/credentials/credentials.h"
#include "auth/gensec/gensec.h"
#include "system/time.h" /* needed by some systems for asctime() */
#include "libcli/resolve/resolve.h"
#include "libcli/security/security.h"
#include "lib/smbreadline/smbreadline.h"
#include "librpc/gen_ndr/ndr_nbt.h"
+#include "param/param.h"
static int io_bufsize = 64512;
/*******************************************************************
Reduce a file name, removing .. elements.
********************************************************************/
-void dos_clean_name(char *s)
+static void dos_clean_name(char *s)
{
char *p=NULL,*r;
****************************************************************************/
static int writefile(int f, const void *_b, int n, BOOL translation)
{
- const uint8_t *b = _b;
+ const uint8_t *b = (const uint8_t *)_b;
int i;
if (!translation) {
****************************************************************************/
static int readfile(void *_b, int n, XFILE *f, BOOL translation)
{
- uint8_t *b = _b;
+ uint8_t *b = (uint8_t *)_b;
int i;
int c;
}
-BOOL mask_match(struct smbcli_state *c, const char *string, const char *pattern,
- BOOL is_case_sensitive)
+static bool mask_match(struct smbcli_state *c, const char *string,
+ const char *pattern, bool is_case_sensitive)
{
char *p2, *s2;
- BOOL ret;
+ bool ret;
if (ISDOTDOT(string))
string = ".";
{
reset_do_list_queue();
do_list_queue_size = 1024;
- do_list_queue = malloc(do_list_queue_size);
+ do_list_queue = malloc_array_p(char, do_list_queue_size);
if (do_list_queue == 0) {
d_printf("malloc fail for size %d\n",
(int)do_list_queue_size);
****************************************************************************/
static void do_list_helper(struct clilist_file_info *f, const char *mask, void *state)
{
- struct smbclient_context *ctx = state;
+ struct smbclient_context *ctx = (struct smbclient_context *)state;
if (f->attrib & FILE_ATTRIBUTE_DIRECTORY) {
if (do_list_dirs && do_this_one(ctx, f)) {
p = strrchr_m(mask2,'\\');
if (!p) return;
p[1] = 0;
- mask2 = talloc_asprintf_append(mask2, "%s\\*", f->name);
+ mask2 = talloc_asprintf_append_buffer(mask2, "%s\\*", f->name);
add_to_do_list_queue(mask2);
}
return;
/* handle directories */
saved_curdir = talloc_strdup(NULL, ctx->remote_cur_dir);
- ctx->remote_cur_dir = talloc_asprintf_append(NULL, "%s\\", finfo->name);
+ ctx->remote_cur_dir = talloc_asprintf_append_buffer(NULL, "%s\\", finfo->name);
string_replace(discard_const_p(char, finfo->name), '\\', '/');
if (ctx->lowercase) {
char *rname;
if (!args[1]) {
- d_printf("put <filename>\n");
+ d_printf("put <filename> [<remotename>]\n");
return 1;
}
- lname = talloc_asprintf(ctx, "%s\\%s", ctx->remote_cur_dir, args[1]);
+ lname = talloc_strdup(ctx, args[1]);
if (args[2])
rname = talloc_strdup(ctx, args[2]);
else
- rname = talloc_strdup(ctx, lname);
+ rname = talloc_asprintf(ctx, "%s\\%s", ctx->remote_cur_dir, lname);
dos_clean_name(rname);
char *fname;
union smb_fileinfo finfo;
NTSTATUS status;
+ int fnum;
if (!args[1]) {
d_printf("allinfo <filename>\n");
d_printf("\tcluster_shift %ld\n", (long)finfo.compression_info.out.cluster_shift);
}
+ /* shadow copies if available */
+ fnum = smbcli_open(ctx->cli->tree, fname, O_RDONLY, DENY_NONE);
+ if (fnum != -1) {
+ struct smb_shadow_copy info;
+ int i;
+ info.in.file.fnum = fnum;
+ info.in.max_data = ~0;
+ status = smb_raw_shadow_data(ctx->cli->tree, ctx, &info);
+ if (NT_STATUS_IS_OK(status)) {
+ d_printf("\tshadow_copy: %u volumes %u names\n",
+ info.out.num_volumes, info.out.num_names);
+ 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);
+ 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,
+ 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));
+ d_printf("\t\tsize: %lu\n", (unsigned long)finfo.all_info.out.size);
+ }
+ }
+ }
+
return 0;
}
****************************************************************************/
static int cmd_history(struct smbclient_context *ctx, const char **args)
{
-#if defined(HAVE_LIBREADLINE)
+#if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST)
HIST_ENTRY **hlist;
int i;
binding = talloc_asprintf(mem_ctx, "ncacn_np:%s", query_host);
status = dcerpc_pipe_connect(mem_ctx, &p, binding,
- &dcerpc_table_srvsvc,
+ &ndr_table_srvsvc,
cmdline_credentials, NULL);
if (!NT_STATUS_IS_OK(status)) {
d_printf("Failed to connect to %s - %s\n",
if (info.count == 2)
info.matches[0] = strdup(info.matches[1]);
else {
- info.matches[0] = malloc(info.samelen+1);
+ info.matches[0] = malloc_array_p(char, info.samelen+1);
if (!info.matches[0])
goto cleanup;
strncpy(info.matches[0], info.matches[1], info.samelen);
matches[0] = strdup(matches[1]);
break;
default:
- matches[0] = malloc(samelen+1);
+ matches[0] = malloc_array_p(char, samelen+1);
if (!matches[0])
goto cleanup;
strncpy(matches[0], matches[1], samelen);
return matches;
cleanup:
- while (i >= 0) {
- free(matches[i]);
- i--;
+ count--;
+ while (count >= 0) {
+ free(matches[count]);
+ count--;
}
free(matches);
return NULL;
ctx->remote_cur_dir = talloc_strdup(ctx, "\\");
status = smbcli_full_connection(ctx, &ctx->cli, server,
- share, NULL, cred, NULL);
+ share, NULL, cred,
+ cli_credentials_get_event_context(cred));
if (!NT_STATUS_IS_OK(status)) {
d_printf("Connection to \\\\%s\\%s failed - %s\n",
server, share, nt_errstr(status));
/****************************************************************************
handle a -L query
****************************************************************************/
-static int do_host_query(const char *query_host)
+static int do_host_query(const char *query_host, const char *workgroup)
{
browse_host(query_host);
- list_servers(lp_workgroup());
+ list_servers(workgroup);
return(0);
}
const char *server_name;
struct smbcli_state *cli;
- make_nbt_name_client(&calling, lp_netbios_name());
+ make_nbt_name_client(&calling, lp_netbios_name(global_loadparm));
nbt_choose_called_name(NULL, &called, desthost, name_type);
POPT_COMMON_CONNECTION
POPT_COMMON_CREDENTIALS
POPT_COMMON_VERSION
- POPT_TABLEEND
+ { NULL }
};
mem_ctx = talloc_init("client.c/main");
}
if (query_host) {
- return do_host_query(query_host);
+ return do_host_query(query_host, lp_workgroup(global_loadparm));
}
if (message) {