Based on an initial patch from H Hasegawa <hasegawa.hiroyuki@fujixerox.co.jp>.
Convert cli_list and associated functions to take calls that return NTSTATUS.
Jeremy.
Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Fri Oct 29 19:40:16 UTC 2010 on sn-devel-104
Display info about a file.
****************************************************************************/
-static void display_finfo(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS display_finfo(struct cli_state *cli_state, struct file_info *finfo,
const char *dir)
{
time_t t;
TALLOC_CTX *ctx = talloc_tos();
+ NTSTATUS status = NT_STATUS_OK;
if (!do_this_one(finfo)) {
- return;
+ return NT_STATUS_OK;
}
t = finfo->mtime_ts.tv_sec; /* the time is assumed to be passed as GMT */
} else {
char *afname = NULL;
uint16_t fnum;
- NTSTATUS status;
/* skip if this is . or .. */
if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
- return;
+ return NT_STATUS_OK;
/* create absolute filename for cli_ntcreate() FIXME */
afname = talloc_asprintf(ctx,
"%s%s%s",
CLI_DIRSEP_STR,
finfo->name);
if (!afname) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
/* print file meta date header */
d_printf( "FILENAME:%s\n", finfo->name);
DEBUG( 0, ("display_finfo() failed to "
"get security descriptor: %s",
cli_errstr(cli_state)));
+ status = cli_nt_error(cli_state);
} else {
display_sec_desc(sd);
}
}
TALLOC_FREE(afname);
}
+ return status;
}
/****************************************************************************
Accumulate size of a file.
****************************************************************************/
-static void do_du(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_du(struct cli_state *cli_state, struct file_info *finfo,
const char *dir)
{
if (do_this_one(finfo)) {
dir_total += finfo->size;
}
+ return NT_STATUS_OK;
}
static bool do_list_recurse;
static long do_list_queue_size = 0;
static long do_list_queue_start = 0;
static long do_list_queue_end = 0;
-static void (*do_list_fn)(struct cli_state *cli_state, struct file_info *,
+static NTSTATUS (*do_list_fn)(struct cli_state *cli_state, struct file_info *,
const char *dir);
/****************************************************************************
A helper for do_list.
****************************************************************************/
-static void do_list_helper(const char *mntpoint, struct file_info *f,
+static NTSTATUS do_list_helper(const char *mntpoint, struct file_info *f,
const char *mask, void *state)
{
struct cli_state *cli_state = (struct cli_state *)state;
TALLOC_CTX *ctx = talloc_tos();
char *dir = NULL;
char *dir_end = NULL;
+ NTSTATUS status = NT_STATUS_OK;
/* Work out the directory. */
dir = talloc_strdup(ctx, mask);
if (!dir) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
if ((dir_end = strrchr(dir, CLI_DIRSEP_CHAR)) != NULL) {
*dir_end = '\0';
if (f->mode & aDIR) {
if (do_list_dirs && do_this_one(f)) {
- do_list_fn(cli_state, f, dir);
+ status = do_list_fn(cli_state, f, dir);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
}
if (do_list_recurse &&
f->name &&
if (!f->name[0]) {
d_printf("Empty dir name returned. Possible server misconfiguration.\n");
TALLOC_FREE(dir);
- return;
+ return NT_STATUS_UNSUCCESSFUL;
}
mask2 = talloc_asprintf(ctx,
mask);
if (!mask2) {
TALLOC_FREE(dir);
- return;
+ return NT_STATUS_NO_MEMORY;
}
p = strrchr_m(mask2,CLI_DIRSEP_CHAR);
if (p) {
CLI_DIRSEP_STR);
if (!mask2) {
TALLOC_FREE(dir);
- return;
+ return NT_STATUS_NO_MEMORY;
}
add_to_do_list_queue(mask2);
TALLOC_FREE(mask2);
}
TALLOC_FREE(dir);
- return;
+ return NT_STATUS_OK;
}
if (do_this_one(f)) {
- do_list_fn(cli_state, f, dir);
+ status = do_list_fn(cli_state, f, dir);
}
TALLOC_FREE(dir);
+ return status;
}
/****************************************************************************
A wrapper around cli_list that adds recursion.
****************************************************************************/
-void do_list(const char *mask,
+NTSTATUS do_list(const char *mask,
uint16 attribute,
- void (*fn)(struct cli_state *cli_state, struct file_info *,
+ NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *,
const char *dir),
bool rec,
bool dirs)
TALLOC_CTX *ctx = talloc_tos();
struct cli_state *targetcli = NULL;
char *targetpath = NULL;
+ NTSTATUS ret_status = NT_STATUS_OK;
+ NTSTATUS status = NT_STATUS_OK;
if (in_do_list && rec) {
fprintf(stderr, "INTERNAL ERROR: do_list called recursively when the recursive flag is true\n");
char *head = talloc_strdup(ctx, do_list_queue_head());
if (!head) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
/* check for dfs */
continue;
}
- cli_list(targetcli, targetpath, attribute,
+ status = cli_list(targetcli, targetpath, attribute,
do_list_helper, targetcli);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("%s listing %s\n",
+ nt_errstr(status), targetpath);
+ ret_status = status;
+ }
remove_do_list_queue_head();
if ((! do_list_queue_empty()) && (fn == display_finfo)) {
char *next_file = do_list_queue_head();
} else {
/* check for dfs */
if (cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetpath)) {
- NTSTATUS status;
status = cli_list(targetcli, targetpath, attribute,
do_list_helper, targetcli);
if (!NT_STATUS_IS_OK(status)) {
d_printf("%s listing %s\n",
nt_errstr(status), targetpath);
+ ret_status = status;
}
TALLOC_FREE(targetpath);
} else {
d_printf("do_list: [%s] %s\n", mask, cli_errstr(cli));
+ ret_status = cli_nt_error(cli);
}
}
in_do_list = 0;
reset_do_list_queue();
+ return ret_status;
}
/****************************************************************************
char *mask = NULL;
char *buf = NULL;
int rc = 1;
+ NTSTATUS status;
dir_total = 0;
mask = talloc_strdup(ctx, client_get_cur_dir());
client_set_cwd(client_get_cur_dir());
}
- do_list(mask, attribute, display_finfo, recurse, true);
+ status = do_list(mask, attribute, display_finfo, recurse, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ return 1;
+ }
rc = do_dskattr();
uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
char *mask = NULL;
char *buf = NULL;
+ NTSTATUS status;
int rc = 1;
dir_total = 0;
mask = talloc_strdup(ctx, "*");
}
- do_list(mask, attribute, do_du, recurse, true);
+ status = do_list(mask, attribute, do_du, recurse, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ return 1;
+ }
rc = do_dskattr();
Do an mget operation on one file.
****************************************************************************/
-static void do_mget(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
const char *dir)
{
TALLOC_CTX *ctx = talloc_tos();
+ NTSTATUS status = NT_STATUS_OK;
char *rname = NULL;
char *quest = NULL;
char *saved_curdir = NULL;
char *new_cd = NULL;
if (!finfo->name) {
- return;
+ return NT_STATUS_OK;
}
if (strequal(finfo->name,".") || strequal(finfo->name,".."))
- return;
+ return NT_STATUS_OK;
if (abort_mget) {
d_printf("mget aborted\n");
- return;
+ return NT_STATUS_UNSUCCESSFUL;
}
if (finfo->mode & aDIR) {
if (asprintf(&quest,
"Get directory %s? ",finfo->name) < 0) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
} else {
if (asprintf(&quest,
"Get file %s? ",finfo->name) < 0) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
}
if (prompt && !yesno(quest)) {
SAFE_FREE(quest);
- return;
+ return NT_STATUS_OK;
}
SAFE_FREE(quest);
client_get_cur_dir(),
finfo->name);
if (!rname) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
do_get(rname, finfo->name, false);
TALLOC_FREE(rname);
- return;
+ return NT_STATUS_OK;
}
/* handle directories */
saved_curdir = talloc_strdup(ctx, client_get_cur_dir());
if (!saved_curdir) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
new_cd = talloc_asprintf(ctx,
finfo->name,
CLI_DIRSEP_STR);
if (!new_cd) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
client_set_cur_dir(new_cd);
mkdir(finfo->name,0777) != 0) {
d_printf("failed to create directory %s\n",finfo->name);
client_set_cur_dir(saved_curdir);
- return;
+ return map_nt_error_from_unix(errno);
}
if (chdir(finfo->name) != 0) {
d_printf("failed to chdir to directory %s\n",finfo->name);
client_set_cur_dir(saved_curdir);
- return;
+ return map_nt_error_from_unix(errno);
}
mget_mask = talloc_asprintf(ctx,
client_get_cur_dir());
if (!mget_mask) {
- return;
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ status = do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
}
- do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true);
if (chdir("..") == -1) {
d_printf("do_mget: failed to chdir to .. (error %s)\n",
strerror(errno) );
+ return map_nt_error_from_unix(errno);
}
client_set_cur_dir(saved_curdir);
TALLOC_FREE(mget_mask);
TALLOC_FREE(saved_curdir);
TALLOC_FREE(new_cd);
+ return NT_STATUS_OK;
}
/****************************************************************************
uint16 attribute = aSYSTEM | aHIDDEN;
char *mget_mask = NULL;
char *buf = NULL;
+ NTSTATUS status = NT_STATUS_OK;
if (recurse) {
attribute |= aDIR;
abort_mget = false;
while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+
mget_mask = talloc_strdup(ctx, client_get_cur_dir());
if (!mget_mask) {
return 1;
if (!mget_mask) {
return 1;
}
- do_list(mget_mask, attribute, do_mget, false, true);
+ status = do_list(mget_mask, attribute, do_mget, false, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ return 1;
+ }
}
if (mget_mask == NULL) {
if (!mget_mask) {
return 1;
}
- do_list(mget_mask, attribute, do_mget, false, true);
+ status = do_list(mget_mask, attribute, do_mget, false, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ return 1;
+ }
}
return 0;
Delete some files.
****************************************************************************/
-static void do_del(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_del(struct cli_state *cli_state, struct file_info *finfo,
const char *dir)
{
TALLOC_CTX *ctx = talloc_tos();
CLI_DIRSEP_CHAR,
finfo->name);
if (!mask) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
if (finfo->mode & aDIR) {
TALLOC_FREE(mask);
- return;
+ return NT_STATUS_OK;
}
status = cli_unlink(cli_state, mask, aSYSTEM | aHIDDEN);
nt_errstr(status), mask);
}
TALLOC_FREE(mask);
+ return status;
}
/****************************************************************************
TALLOC_CTX *ctx = talloc_tos();
char *mask = NULL;
char *buf = NULL;
+ NTSTATUS status = NT_STATUS_OK;
uint16 attribute = aSYSTEM | aHIDDEN;
if (recurse) {
return 1;
}
- do_list(mask,attribute,do_del,false,false);
+ status = do_list(mask,attribute,do_del,false,false);
+ if (!NT_STATUS_IS_OK(status)) {
+ return 1;
+ }
return 0;
}
int len;
};
-static void completion_remote_filter(const char *mnt,
+static NTSTATUS completion_remote_filter(const char *mnt,
struct file_info *f,
const char *mask,
void *state)
struct completion_remote *info = (struct completion_remote *)state;
if (info->count >= MAX_COMPLETIONS - 1) {
- return;
+ return NT_STATUS_OK;
}
if (strncmp(info->text, f->name, info->len) != 0) {
- return;
+ return NT_STATUS_OK;
}
if (ISDOT(f->name) || ISDOTDOT(f->name)) {
- return;
+ return NT_STATUS_OK;
}
if ((info->dirmask[0] == 0) && !(f->mode & aDIR))
tmp = talloc_strdup(ctx,info->dirmask);
if (!tmp) {
TALLOC_FREE(ctx);
- return;
+ return NT_STATUS_NO_MEMORY;
}
tmp = talloc_asprintf_append(tmp, "%s", f->name);
if (!tmp) {
TALLOC_FREE(ctx);
- return;
+ return NT_STATUS_NO_MEMORY;
}
if (f->mode & aDIR) {
tmp = talloc_asprintf_append(tmp, "%s",
}
if (!tmp) {
TALLOC_FREE(ctx);
- return;
+ return NT_STATUS_NO_MEMORY;
}
info->matches[info->count] = SMB_STRDUP(tmp);
TALLOC_FREE(ctx);
}
if (info->matches[info->count] == NULL) {
- return;
+ return NT_STATUS_OK;
}
if (f->mode & aDIR) {
smb_readline_ca_char(0);
}
}
info->count++;
+ return NT_STATUS_OK;
}
static char **remote_completion(const char *text, int len)
const char *client_get_cur_dir(void);
const char *client_set_cur_dir(const char *newdir);
-void do_list(const char *mask,
+NTSTATUS do_list(const char *mask,
uint16 attribute,
- void (*fn)(struct cli_state *cli_state, struct file_info *,
+ NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *,
const char *dir),
bool rec,
bool dirs);
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,
+static NTSTATUS do_atar(const char *rname_in, char *lname,
struct file_info *finfo1);
-static void do_tar(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_tar(struct cli_state *cli_state, struct file_info *finfo,
const char *dir);
static void oct_it(uint64_t value, int ndgs, char *p);
static void fixtarname(char *tptr, const char *fp, size_t l);
append one remote file to the tar file
***************************************************************************/
-static void do_atar(const char *rname_in, char *lname,
+static NTSTATUS do_atar(const char *rname_in, char *lname,
struct file_info *finfo1)
{
uint16_t fnum = (uint16_t)-1;
int datalen=0;
char *rname = NULL;
TALLOC_CTX *ctx = talloc_stackframe();
-
+ NTSTATUS status = NT_STATUS_OK;
struct timespec tp_start;
clock_gettime_mono(&tp_start);
data = SMB_MALLOC_ARRAY(char, read_size);
if (!data) {
DEBUG(0,("do_atar: out of memory.\n"));
+ status = NT_STATUS_NO_MEMORY;
goto cleanup;
}
rname = clean_name(ctx, rname_in);
if (!rname) {
+ status = NT_STATUS_NO_MEMORY;
goto cleanup;
}
- if (!NT_STATUS_IS_OK(cli_open(cli, rname, O_RDONLY, DENY_NONE, &fnum))) {
+ status = cli_open(cli, rname, O_RDONLY, DENY_NONE, &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("%s opening remote file %s (%s)\n",
cli_errstr(cli),rname, client_get_cur_dir()));
goto cleanup;
finfo.name = string_create_s(strlen(rname));
if (finfo.name == NULL) {
DEBUG(0, ("Unable to allocate space for finfo.name in do_atar\n"));
+ status = NT_STATUS_NO_MEMORY;
goto cleanup;
}
if (datalen == -1) {
DEBUG(0,("Error reading file %s : %s\n", rname, cli_errstr(cli)));
+ status = cli_nt_error(cli);
break;
}
if (dotarbuf(tarhandle,data,datalen) != datalen) {
DEBUG(0,("Error writing to tar file - %s\n", strerror(errno)));
+ status = map_nt_error_from_unix(errno);
break;
}
if ( (datalen == 0) && (finfo.size != 0) ) {
+ status = NT_STATUS_UNSUCCESSFUL;
DEBUG(0,("Error reading file %s. Got 0 bytes\n", rname));
break;
}
if (nread < finfo.size) {
DEBUG(0, ("Didn't get entire file. size=%.0f, nread=%d\n",
(double)finfo.size, (int)nread));
- if (padit(data, (uint64_t)sizeof(data), finfo.size - nread))
+ if (padit(data, (uint64_t)sizeof(data), finfo.size - nread)) {
+ status = map_nt_error_from_unix(errno);
DEBUG(0,("Error writing tar file - %s\n", strerror(errno)));
+ }
}
/* round tar file to nearest block */
} else {
DEBUG(4, ("skipping %s - initial read failed (file was locked ?)\n", finfo.name));
shallitime=0;
+ status = NT_STATUS_UNSUCCESSFUL;
}
}
}
TALLOC_FREE(ctx);
SAFE_FREE(data);
+ return status;
}
/****************************************************************************
Append single file to tar file (or not)
***************************************************************************/
-static void do_tar(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_tar(struct cli_state *cli_state, struct file_info *finfo,
const char *dir)
{
TALLOC_CTX *ctx = talloc_stackframe();
+ NTSTATUS status = NT_STATUS_OK;
if (strequal(finfo->name,"..") || strequal(finfo->name,"."))
- return;
+ return NT_STATUS_OK;
/* Is it on the exclude list ? */
if (!tar_excl && clipn) {
client_get_cur_dir(),
finfo->name);
if (!exclaim) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
DEBUG(5, ("...tar_re_search: %d\n", tar_re_search));
(tar_re_search && mask_match_list(exclaim, cliplist, clipn, True))) {
DEBUG(3,("Skipping file %s\n", exclaim));
TALLOC_FREE(exclaim);
- return;
+ return NT_STATUS_OK;
}
TALLOC_FREE(exclaim);
}
saved_curdir = talloc_strdup(ctx, client_get_cur_dir());
if (!saved_curdir) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
DEBUG(5, ("strlen(cur_dir)=%d, \
client_get_cur_dir(),
finfo->name);
if (!new_cd) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
client_set_cur_dir(new_cd);
"%s*",
client_get_cur_dir());
if (!mtar_mask) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
DEBUG(5, ("Doing list with mtar_mask: %s\n", mtar_mask));
- do_list(mtar_mask, attribute, do_tar, False, True);
+ status = do_list(mtar_mask, attribute, do_tar, False, True);
client_set_cur_dir(saved_curdir);
TALLOC_FREE(saved_curdir);
TALLOC_FREE(new_cd);
client_get_cur_dir(),
finfo->name);
if (!rname) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
- do_atar(rname,finfo->name,finfo);
+ status = do_atar(rname,finfo->name,finfo);
TALLOC_FREE(rname);
}
+ return status;
}
/****************************************************************************
/* The following definitions come from libsmb/clilist.c */
NTSTATUS cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute,
- void (*fn)(const char *, struct file_info *,
+ NTSTATUS (*fn)(const char *, struct file_info *,
const char *, void *), void *state);
NTSTATUS cli_list_trans(struct cli_state *cli, const char *mask,
uint16_t attribute, int info_level,
- void (*fn)(const char *mnt, struct file_info *finfo,
+ NTSTATUS (*fn)(const char *mnt, struct file_info *finfo,
const char *mask, void *private_data),
void *private_data);
struct tevent_req *cli_list_send(TALLOC_CTX *mem_ctx,
NTSTATUS cli_list_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
struct file_info **finfo, size_t *num_finfo);
NTSTATUS cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
- void (*fn)(const char *, struct file_info *, const char *,
+ NTSTATUS (*fn)(const char *, struct file_info *, const char *,
void *), void *state);
/* The following definitions come from libsmb/climessage.c */
uint16_t attribute;
};
-static void gpo_sync_func(const char *mnt,
+static NTSTATUS gpo_sync_func(const char *mnt,
struct file_info *info,
const char *mask,
void *state);
static NTSTATUS gpo_copy_dir(const char *unix_path)
{
if ((mkdir(unix_path, 0644)) < 0 && errno != EEXIST) {
- return NT_STATUS_ACCESS_DENIED;
+ return map_nt_error_from_unix(errno);
}
return NT_STATUS_OK;
sync files
****************************************************************/
-static bool gpo_sync_files(struct sync_context *ctx)
+static NTSTATUS gpo_sync_files(struct sync_context *ctx)
{
NTSTATUS status;
if (!NT_STATUS_IS_OK(status)) {
DEBUG(1, ("listing [%s] failed with error: %s\n",
ctx->mask, nt_errstr(status)));
- return false;
+ return status;
}
- return true;
+ return status;
}
/****************************************************************
syncronisation call back
****************************************************************/
-static void gpo_sync_func(const char *mnt,
+static NTSTATUS gpo_sync_func(const char *mnt,
struct file_info *info,
const char *mask,
void *state)
ctx = (struct sync_context *)state;
if (strequal(info->name, ".") || strequal(info->name, "..")) {
- return;
+ return NT_STATUS_OK;
}
DEBUG(5,("gpo_sync_func: got mask: [%s], name: [%s]\n",
if (!NT_STATUS_IS_OK(result)) {
DEBUG(1,("failed to copy dir: %s\n",
nt_errstr(result)));
+ return result;
}
old_nt_dir = ctx->remote_path;
nt_dir);
if (!ctx->local_path || !ctx->mask || !ctx->remote_path) {
DEBUG(0,("gpo_sync_func: ENOMEM\n"));
- return;
+ return NT_STATUS_NO_MEMORY;
}
- if (!gpo_sync_files(ctx)) {
+ result = gpo_sync_files(ctx);
+ if (!NT_STATUS_IS_OK(result)) {
DEBUG(0,("could not sync files\n"));
+ return result;
}
ctx->remote_path = old_nt_dir;
ctx->local_path = old_unix_dir;
- return;
+ return NT_STATUS_OK;
}
DEBUG(3,("got file: [%s]\n", info->name));
DEBUG(1,("failed to copy file: %s\n",
nt_errstr(result)));
}
+ return result;
}
return NT_STATUS_NO_MEMORY;
}
- if (!gpo_sync_files(&ctx)) {
- return NT_STATUS_NO_SUCH_FILE;
- }
-
- return NT_STATUS_OK;
+ return gpo_sync_files(&ctx);
}
NTSTATUS cli_list_old(struct cli_state *cli, const char *mask,
uint16 attribute,
- void (*fn)(const char *, struct file_info *,
+ NTSTATUS (*fn)(const char *, struct file_info *,
const char *, void *), void *state)
{
TALLOC_CTX *frame = talloc_stackframe();
}
num_finfo = talloc_array_length(finfo);
for (i=0; i<num_finfo; i++) {
- fn(cli->dfs_mountpoint, &finfo[i], mask, state);
+ status = fn(cli->dfs_mountpoint, &finfo[i], mask, state);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto fail;
+ }
}
fail:
TALLOC_FREE(frame);
NTSTATUS cli_list_trans(struct cli_state *cli, const char *mask,
uint16_t attribute, int info_level,
- void (*fn)(const char *mnt, struct file_info *finfo,
+ NTSTATUS (*fn)(const char *mnt, struct file_info *finfo,
const char *mask, void *private_data),
void *private_data)
{
}
num_finfo = talloc_array_length(finfo);
for (i=0; i<num_finfo; i++) {
- fn(cli->dfs_mountpoint, &finfo[i], mask, private_data);
+ status = fn(cli->dfs_mountpoint, &finfo[i], mask, private_data);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto fail;
+ }
}
fail:
TALLOC_FREE(frame);
}
NTSTATUS cli_list(struct cli_state *cli, const char *mask, uint16 attribute,
- void (*fn)(const char *, struct file_info *, const char *,
+ NTSTATUS (*fn)(const char *, struct file_info *, const char *,
void *), void *state)
{
TALLOC_CTX *frame = talloc_stackframe();
}
for (i=0; i<num_finfo; i++) {
- fn(cli->dfs_mountpoint, &finfo[i], mask, state);
+ status = fn(cli->dfs_mountpoint, &finfo[i], mask, state);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto fail;
+ }
}
fail:
TALLOC_FREE(frame);
dirent_type = dir->dir_type;
if (add_dirent(dir, name, comment, dirent_type) < 0) {
-
/* An error occurred, what do we do? */
/* FIXME: Add some code here */
+ /* Change cli_NetServerEnum to take a fn
+ returning NTSTATUS... JRA. */
}
/* Point to the one just added */
}
if (add_dirent(dir, name, comment, dirent_type) < 0) {
-
/* An error occurred, what do we do? */
/* FIXME: Add some code here */
-
+ /* Change cli_NetServerEnum to take a fn
+ returning NTSTATUS... JRA. */
}
}
-static void
+static NTSTATUS
dir_list_fn(const char *mnt,
struct file_info *finfo,
const char *mask,
if (add_dirent((SMBCFILE *)state, finfo->name, "",
(finfo->mode&aDIR?SMBC_DIR:SMBC_FILE)) < 0) {
-
- /* Handle an error ... */
-
- /* FIXME: Add some code ... */
-
+ SMBCFILE *dir = (SMBCFILE *)state;
+ return map_nt_error_from_unix(dir->dir_error);
}
-
+ return NT_STATUS_OK;
}
static int
* Our list function simply checks to see if a directory is not empty
*/
-static void
+static NTSTATUS
rmdir_list_fn(const char *mnt,
struct file_info *finfo,
const char *mask,
bool *smbc_rmdir_dirempty = (bool *)state;
*smbc_rmdir_dirempty = false;
}
+ return NT_STATUS_OK;
}
/*
char *short_name;
};
-static void listfn(const char *mnt, struct file_info *f, const char *s,
+static NTSTATUS listfn(const char *mnt, struct file_info *f, const char *s,
void *private_data)
{
struct rn_state *state = (struct rn_state *)private_data;
resultp[2] = '+';
}
- if ((state == NULL) || ISDOT(f->name) || ISDOTDOT(f->name)) {
- return;
+ if (state == NULL) {
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+
+ if (ISDOT(f->name) || ISDOTDOT(f->name)) {
+ return NT_STATUS_OK;
}
fstrcpy(state->short_name, f->short_name);
strlower_m(state->short_name);
*state->pp_long_name = SMB_STRDUP(f->name);
if (!*state->pp_long_name) {
- return;
+ return NT_STATUS_NO_MEMORY;
}
strlower_m(*state->pp_long_name);
+ return NT_STATUS_OK;
}
static void get_real_name(struct cli_state *cli,
cli_dskattr(c, &bsize, &total, &avail);
}
-static void find_fn(const char *mnt, struct file_info *finfo, const char *name,
+static NTSTATUS find_fn(const char *mnt, struct file_info *finfo, const char *name,
void *state)
{
/* noop */
+ return NT_STATUS_OK;
}
void nb_findfirst(const char *mask)
static int total_deleted;
-static void delete_fn(const char *mnt, struct file_info *finfo,
+static NTSTATUS delete_fn(const char *mnt, struct file_info *finfo,
const char *name, void *state)
{
+ NTSTATUS status;
char *s, *n;
if (finfo->name[0] == '.') return;
n[strlen(n)-1] = 0;
if (asprintf(&s, "%s%s", n, finfo->name) == -1) {
printf("asprintf failed\n");
- return;
+ return NT_STATUS_NO_MEMORY;
}
if (finfo->mode & aDIR) {
char *s2;
if (asprintf(&s2, "%s\\*", s) == -1) {
printf("asprintf failed\n");
- return;
+ return NT_STATUS_NO_MEMORY;
+ }
+ status = cli_list(c, s2, aDIR, delete_fn, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ free(n);
+ free(s2);
+ return status;
}
- cli_list(c, s2, aDIR, delete_fn, NULL);
nb_rmdir(s);
} else {
total_deleted++;
}
free(s);
free(n);
+ return NT_STATUS_OK;
}
void nb_deltree(const char *dname)
return correct;
}
-static void list_fn(const char *mnt, struct file_info *finfo,
+static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
const char *name, void *state)
{
int *matched = (int *)state;
if (matched != NULL) {
*matched += 1;
}
+ return NT_STATUS_OK;
}
/*
return correct;
}
-static void del_fn(const char *mnt, struct file_info *finfo, const char *mask,
+static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
void *state)
{
struct cli_state *pcli = (struct cli_state *)state;
slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
- return;
+ return NT_STATUS_OK;
if (finfo->mode & aDIR) {
if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
printf("del_fn: failed to unlink %s\n,", fname );
}
+ return NT_STATUS_OK;
}
static const char *illegal_chars = "*\\/?<>|\":";
static char force_shortname_chars[] = " +,.[];=\177";
-static void shortname_del_fn(const char *mnt, struct file_info *finfo,
+static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
const char *mask, void *state)
{
struct cli_state *pcli = (struct cli_state *)state;
fstring fname;
+ NTSTATUS status = NT_STATUS_OK;
+
slprintf(fname, sizeof(fname), "\\shortname\\%s", finfo->name);
if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
- return;
+ return NT_STATUS_OK;
if (finfo->mode & aDIR) {
- if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
+ status = cli_rmdir(pcli, fname);
+ if (!NT_STATUS_IS_OK(status)) {
printf("del_fn: failed to rmdir %s\n,", fname );
+ }
} else {
- if (!NT_STATUS_IS_OK(cli_unlink(pcli, fname, aSYSTEM | aHIDDEN)))
+ status = cli_unlink(pcli, fname, aSYSTEM | aHIDDEN);
+ if (!NT_STATUS_IS_OK(status)) {
printf("del_fn: failed to unlink %s\n,", fname );
+ }
}
+ return status;
}
struct sn_state {
bool val;
};
-static void shortname_list_fn(const char *mnt, struct file_info *finfo,
+static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
const char *name, void *state)
{
struct sn_state *s = (struct sn_state *)state;
s->val = true;
}
s->matched += 1;
+ return NT_STATUS_OK;
}
static bool run_shortname_test(int dummy)
#include "../libcli/security/security.h"
static int net_mode_share;
-static bool sync_files(struct copy_clistate *cp_clistate, const char *mask);
+static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask);
/**
* @file net_rpc.c
* @param state arg-pointer
*
**/
-static void copy_fn(const char *mnt, struct file_info *f,
+static NTSTATUS copy_fn(const char *mnt, struct file_info *f,
const char *mask, void *state)
{
static NTSTATUS nt_status;
c = local_state->c;
if (strequal(f->name, ".") || strequal(f->name, ".."))
- return;
+ return NT_STATUS_OK;
DEBUG(3,("got mask: %s, name: %s\n", mask, f->name));
break;
default:
d_fprintf(stderr, _("Unsupported mode %d\n"), net_mode_share);
- return;
+ return NT_STATUS_INTERNAL_ERROR;
}
- if (!NT_STATUS_IS_OK(nt_status))
+ if (!NT_STATUS_IS_OK(nt_status)) {
printf(_("could not handle dir %s: %s\n"),
dir, nt_errstr(nt_status));
+ return nt_status;
+ }
/* search below that directory */
fstrcpy(new_mask, dir);
old_dir = local_state->cwd;
local_state->cwd = dir;
- if (!sync_files(local_state, new_mask))
+ nt_status = sync_files(local_state, new_mask);
+ if (!NT_STATUS_IS_OK(nt_status)) {
printf(_("could not handle files\n"));
+ }
local_state->cwd = old_dir;
- return;
+ return nt_status;
}
default:
d_fprintf(stderr, _("Unsupported file mode %d\n"),
net_mode_share);
- return;
+ return NT_STATUS_INTERNAL_ERROR;
}
if (!NT_STATUS_IS_OK(nt_status))
printf(_("could not handle file %s: %s\n"),
filename, nt_errstr(nt_status));
-
+ return nt_status;
}
/**
*
* @return Boolean result
**/
-static bool sync_files(struct copy_clistate *cp_clistate, const char *mask)
+static NTSTATUS sync_files(struct copy_clistate *cp_clistate, const char *mask)
{
struct cli_state *targetcli;
char *targetpath = NULL;
d_fprintf(stderr, _("cli_resolve_path %s failed with error: "
"%s\n"),
mask, cli_errstr(cp_clistate->cli_share_src));
- return false;
+ return cli_nt_error(cp_clistate->cli_share_src);
}
status = cli_list(targetcli, targetpath, cp_clistate->attribute,
if (!NT_STATUS_IS_OK(status)) {
d_fprintf(stderr, _("listing %s failed with error: %s\n"),
mask, nt_errstr(status));
- return false;
}
- return true;
+ return status;
}
goto done;
}
- if (!sync_files(&cp_clistate, mask)) {
+ nt_status = sync_files(&cp_clistate, mask);
+ if (!NT_STATUS_IS_OK(nt_status)) {
d_fprintf(stderr, _("could not handle files for share: "
"%s\n"), info502.name);
- nt_status = NT_STATUS_UNSUCCESSFUL;
goto done;
}
}