s3-libgpo: move group policy protos to where they belong.
[sfrench/samba-autobuild/.git] / source3 / libgpo / gpo_filesync.c
index c4b65210c1763c50497ec81984dc6bbadeec8d09..a3002fe860667b3c8c7468a5700d1c438006b47d 100644 (file)
  */
 
 #include "includes.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;
 };
 
@@ -39,15 +41,15 @@ NTSTATUS gpo_copy_file(TALLOC_CTX *mem_ctx,
                       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;
        }
 
@@ -82,7 +84,7 @@ NTSTATUS gpo_copy_file(TALLOC_CTX *mem_ctx,
        if (fnum) {
                cli_close(cli, fnum);
        }
-       if (fd) {
+       if (fd != -1) {
                close(fd);
        }
 
@@ -117,10 +119,10 @@ static bool gpo_sync_files(struct sync_context *ctx)
                     ctx) == -1) {
                DEBUG(1,("listing [%s] failed with error: %s\n",
                        ctx->mask, cli_errstr(ctx->cli)));
-               return False;
+               return false;
        }
 
-       return True;
+       return true;
 }
 
 /****************************************************************
@@ -166,14 +168,18 @@ static void gpo_sync_func(const char *mnt,
                }
 
                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, "\\*");
-
+               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;
+               }
                if (!gpo_sync_files(ctx)) {
                        DEBUG(0,("could not sync files\n"));
                }
@@ -219,8 +225,12 @@ NTSTATUS gpo_sync_directories(TALLOC_CTX *mem_ctx,
        ctx.local_path  = CONST_DISCARD(char *, local_path);
        ctx.attribute   = (aSYSTEM | aHIDDEN | aDIR);
 
-       pstrcpy(ctx.mask, nt_path);
-       pstrcat(ctx.mask, "\\*");
+       ctx.mask = talloc_asprintf(mem_ctx,
+                               "%s\\*",
+                               nt_path);
+       if (!ctx.mask) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        if (!gpo_sync_files(&ctx)) {
                return NT_STATUS_NO_SUCH_FILE;