*/
#include "includes.h"
+#include "popt_common.h"
#include "libsmbclient.h"
#include "libsmb_internal.h"
-
+#include "../librpc/gen_ndr/cli_srvsvc.h"
/*
* Routine to open a directory
static void
dir_list_fn(const char *mnt,
- file_info *finfo,
+ struct file_info *finfo,
const char *mask,
void *state)
{
struct srvsvc_NetShareCtr1 ctr1;
fstring name = "";
fstring comment = "";
- struct rpc_pipe_client *pipe_hnd;
+ struct rpc_pipe_client *pipe_hnd = NULL;
NTSTATUS nt_status;
uint32_t resume_handle = 0;
uint32_t total_entries = 0;
}
/* For each returned entry... */
- for (i = 0; i < total_entries; i++) {
+ for (i = 0; i < info_ctr.ctr.ctr1->count; i++) {
/* pull out the share name */
fstrcpy(name, info_ctr.ctr.ctr1->array[i].name);
*/
if (!srv &&
!is_ipaddress(server) &&
- (resolve_name(server, &rem_ss, 0x1d) || /* LMB */
- resolve_name(server, &rem_ss, 0x1b) )) { /* DMB */
-
+ (resolve_name(server, &rem_ss, 0x1d, false) || /* LMB */
+ resolve_name(server, &rem_ss, 0x1b, false) )) { /* DMB */
+ /*
+ * "server" is actually a workgroup name,
+ * not a server. Make this clear.
+ */
+ char *wgroup = server;
fstring buserver;
dir->dir_type = SMBC_SERVER;
/*
* Get the backup list ...
*/
- if (!name_status_find(server, 0, 0,
+ if (!name_status_find(wgroup, 0, 0,
&rem_ss, buserver)) {
+ char addr[INET6_ADDRSTRLEN];
+ print_sockaddr(addr, sizeof(addr), &rem_ss);
DEBUG(0,("Could not get name of "
- "local/domain master browser "
- "for server %s\n", server));
+ "local/domain master browser "
+ "for workgroup %s from "
+ "address %s\n",
+ wgroup,
+ addr));
if (dir) {
SAFE_FREE(dir->fname);
SAFE_FREE(dir);
dir->srv = srv;
/* Now, list the servers ... */
- if (!cli_NetServerEnum(srv->cli, server,
+ if (!cli_NetServerEnum(srv->cli, wgroup,
0x0000FFFE, list_fn,
(void *)dir)) {
return NULL;
}
} else if (srv ||
- (resolve_name(server, &rem_ss, 0x20))) {
+ (resolve_name(server, &rem_ss, 0x20, false))) {
/*
* If we hadn't found the server, get one now
*/
char *targetpath;
struct cli_state *targetcli;
+ NTSTATUS status;
/* We connect to the server and list the directory */
dir->dir_type = SMBC_FILE_SHARE;
return NULL;
}
- if (cli_list(targetcli, targetpath,
- aDIR | aSYSTEM | aHIDDEN,
- dir_list_fn, (void *)dir) < 0) {
-
+ status = cli_list(targetcli, targetpath,
+ aDIR | aSYSTEM | aHIDDEN,
+ dir_list_fn, (void *)dir);
+ if (!NT_STATUS_IS_OK(status)) {
if (dir) {
SAFE_FREE(dir->fname);
SAFE_FREE(dir);
}
/*d_printf(">>>mkdir: resolved path as %s\n", targetpath);*/
- if (!cli_mkdir(targetcli, targetpath)) {
-
+ if (!NT_STATUS_IS_OK(cli_mkdir(targetcli, targetpath))) {
errno = SMBC_errno(context, targetcli);
TALLOC_FREE(frame);
return -1;
static void
rmdir_list_fn(const char *mnt,
- file_info *finfo,
+ struct file_info *finfo,
const char *mask,
void *state)
{
}
/*d_printf(">>>rmdir: resolved path as %s\n", targetpath);*/
-
- if (!cli_rmdir(targetcli, targetpath)) {
+ if (!NT_STATUS_IS_OK(cli_rmdir(targetcli, targetpath))) {
errno = SMBC_errno(context, targetcli);
/* Local storage to avoid buffer overflows */
char *lpath;
bool smbc_rmdir_dirempty = true;
+ NTSTATUS status;
lpath = talloc_asprintf(frame, "%s\\*",
targetpath);
return -1;
}
- if (cli_list(targetcli, lpath,
- aDIR | aSYSTEM | aHIDDEN,
- rmdir_list_fn,
- &smbc_rmdir_dirempty) < 0) {
+ status = cli_list(targetcli, lpath,
+ aDIR | aSYSTEM | aHIDDEN,
+ rmdir_list_fn,
+ &smbc_rmdir_dirempty);
+ if (!NT_STATUS_IS_OK(status)) {
/* Fix errno to ignore latest error ... */
DEBUG(5, ("smbc_rmdir: "
"cli_list returned an error: %d\n",
if ((newmode & S_IXGRP) && lp_map_system(-1)) mode |= aSYSTEM;
if ((newmode & S_IXOTH) && lp_map_hidden(-1)) mode |= aHIDDEN;
- if (!cli_setatr(targetcli, targetpath, mode, 0)) {
+ if (!NT_STATUS_IS_OK(cli_setatr(targetcli, targetpath, mode, 0))) {
errno = SMBC_errno(context, targetcli);
TALLOC_FREE(frame);
return -1;
}
/*d_printf(">>>unlink: resolved path as %s\n", targetpath);*/
- if (!cli_unlink(targetcli, targetpath)) {
+ if (!NT_STATUS_IS_OK(cli_unlink(targetcli, targetpath, aSYSTEM | aHIDDEN))) {
errno = SMBC_errno(context, targetcli);
return -1;
}
- if (!cli_rename(targetcli1, targetpath1, targetpath2)) {
+ if (!NT_STATUS_IS_OK(cli_rename(targetcli1, targetpath1, targetpath2))) {
int eno = SMBC_errno(ocontext, targetcli1);
if (eno != EEXIST ||
- !cli_unlink(targetcli1, targetpath2) ||
- !cli_rename(targetcli1, targetpath1, targetpath2)) {
+ !NT_STATUS_IS_OK(cli_unlink(targetcli1, targetpath2, aSYSTEM | aHIDDEN)) ||
+ !NT_STATUS_IS_OK(cli_rename(targetcli1, targetpath1, targetpath2))) {
errno = eno;
TALLOC_FREE(frame);