*/
#include "includes.h"
+#include "system/filesys.h"
+#include "../libgpo/gpo.h"
+#include "libgpo/gpo_proto.h"
struct sync_context {
TALLOC_CTX *mem_ctx;
struct cli_state *cli;
char *remote_path;
char *local_path;
- pstring mask;
+ char *mask;
uint16_t attribute;
};
-static void gpo_sync_func(const char *mnt,
- file_info *info,
+static NTSTATUS gpo_sync_func(const char *mnt,
+ struct file_info *info,
const char *mask,
void *state);
const char *unix_path)
{
NTSTATUS result;
- int fnum;
- int fd = 0;
+ uint16_t fnum;
+ int fd = -1;
char *data = NULL;
static int io_bufsize = 64512;
int read_size = io_bufsize;
off_t nread = 0;
- if ((fnum = cli_open(cli, nt_path, O_RDONLY, DENY_NONE)) == -1) {
- result = NT_STATUS_NO_SUCH_FILE;
+ result = cli_open(cli, nt_path, O_RDONLY, DENY_NONE, &fnum);
+ if (!NT_STATUS_IS_OK(result)) {
goto out;
}
if (fnum) {
cli_close(cli, fnum);
}
- if (fd) {
+ if (fd != -1) {
close(fd);
}
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;
+
DEBUG(3,("calling cli_list with mask: %s\n", ctx->mask));
- if (cli_list(ctx->cli,
- ctx->mask,
- ctx->attribute,
- gpo_sync_func,
- ctx) == -1) {
- DEBUG(1,("listing [%s] failed with error: %s\n",
- ctx->mask, cli_errstr(ctx->cli)));
- return False;
+ status = cli_list(ctx->cli, ctx->mask, ctx->attribute, gpo_sync_func,
+ ctx);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1, ("listing [%s] failed with error: %s\n",
+ ctx->mask, nt_errstr(status)));
+ return status;
}
- return True;
+ return status;
}
/****************************************************************
syncronisation call back
****************************************************************/
-static void gpo_sync_func(const char *mnt,
- file_info *info,
+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;
- ctx->remote_path = nt_dir;
+ ctx->remote_path = talloc_strdup(ctx->mem_ctx, nt_dir);
old_unix_dir = ctx->local_path;
ctx->local_path = talloc_strdup(ctx->mem_ctx, unix_dir);
- pstrcpy(ctx->mask, nt_dir);
- pstrcat(ctx->mask, "\\*");
-
- if (!gpo_sync_files(ctx)) {
+ ctx->mask = talloc_asprintf(ctx->mem_ctx,
+ "%s\\*",
+ nt_dir);
+ if (!ctx->local_path || !ctx->mask || !ctx->remote_path) {
+ DEBUG(0,("gpo_sync_func: ENOMEM\n"));
+ return NT_STATUS_NO_MEMORY;
+ }
+ 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;
}
ctx.local_path = CONST_DISCARD(char *, local_path);
ctx.attribute = (aSYSTEM | aHIDDEN | aDIR);
- pstrcpy(ctx.mask, nt_path);
- pstrcat(ctx.mask, "\\*");
-
- if (!gpo_sync_files(&ctx)) {
- return NT_STATUS_NO_SUCH_FILE;
+ ctx.mask = talloc_asprintf(mem_ctx,
+ "%s\\*",
+ nt_path);
+ if (!ctx.mask) {
+ return NT_STATUS_NO_MEMORY;
}
- return NT_STATUS_OK;
+ return gpo_sync_files(&ctx);
}