summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorJim McDonough <jmcd@samba.org>2006-03-23 16:39:37 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:15:43 -0500
commita0e36ddb688d88e60a50c90c170cdb861e6a7013 (patch)
treeeb15c9ae3f770c9f7a003658ce7055ff7cef2da4 /source3/utils
parentaa583e5912866069f1f79e0b675e9e7927c64fbe (diff)
downloadsamba-a0e36ddb688d88e60a50c90c170cdb861e6a7013.tar.gz
samba-a0e36ddb688d88e60a50c90c170cdb861e6a7013.tar.bz2
samba-a0e36ddb688d88e60a50c90c170cdb861e6a7013.zip
r14681: Get rid of hardcoded /tmp/add.ldif and /tmp/mod.ldif files. Is there a
different directory the temp files should be in, or is /tmp ok? Still have to get rid of the output file hardcoding, but that is to come, because I need to cleanup stdout. (This used to be commit 0d4bd93a5ca4025bbdeb507f4a2d6217cfb39c79)
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_rpc_samsync.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/source3/utils/net_rpc_samsync.c b/source3/utils/net_rpc_samsync.c
index 9b001e02f3..ae8d2cdc08 100644
--- a/source3/utils/net_rpc_samsync.c
+++ b/source3/utils/net_rpc_samsync.c
@@ -1719,7 +1719,9 @@ static NTSTATUS fetch_database_to_ldif(struct rpc_pipe_client *pipe_hnd,
{
char *suffix;
const char *builtin_sid = "S-1-5-32";
- char *ldif_file;
+ char *ldif_file, *add_ldif, *mod_ldif;
+ const char *add_template = "/tmp/add.ldif.XXXXXX";
+ const char *mod_template = "/tmp/mod.ldif.XXXXXX";
fstring sid, domainname;
uint32 sync_context = 0;
NTSTATUS ret = NT_STATUS_OK, result;
@@ -1728,7 +1730,6 @@ static NTSTATUS fetch_database_to_ldif(struct rpc_pipe_client *pipe_hnd,
SAM_DELTA_HDR *hdr_deltas;
SAM_DELTA_CTR *deltas;
uint32 num_deltas;
- const char *add_ldif = "/tmp/add.ldif", *mod_ldif = "/tmp/mod.ldif";
FILE *add_fd = NULL, *mod_fd = NULL, *ldif_fd = NULL;
char sys_cmd[1024];
int num_alloced = 0, g_index = 0, a_index = 0, sys_cmd_result;
@@ -1751,18 +1752,20 @@ static NTSTATUS fetch_database_to_ldif(struct rpc_pipe_client *pipe_hnd,
else
ldif_file = talloc_strdup(mem_ctx, "/tmp/tmp.ldif");
- if (ldif_file == NULL) {
+ add_ldif = talloc_strdup(mem_ctx, add_template);
+ mod_ldif = talloc_strdup(mem_ctx, mod_template);
+ if (!ldif_file || !add_ldif || !mod_ldif) {
ret = NT_STATUS_NO_MEMORY;
goto done;
}
/* Open the add and mod ldif files */
- if (!(add_fd = fopen(add_ldif, "a"))) {
+ if (!(add_fd = fdopen(smb_mkstemp(add_ldif),"w"))) {
DEBUG(1, ("Could not open %s\n", add_ldif));
ret = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- if (!(mod_fd = fopen(mod_ldif, "a"))) {
+ if (!(mod_fd = fdopen(smb_mkstemp(mod_ldif),"w"))) {
DEBUG(1, ("Could not open %s\n", mod_ldif));
ret = NT_STATUS_UNSUCCESSFUL;
goto done;
@@ -1993,20 +1996,22 @@ static NTSTATUS fetch_database_to_ldif(struct rpc_pipe_client *pipe_hnd,
goto done;
}
- /* Delete the temporary ldif files */
- if (unlink(add_ldif))
- d_fprintf(stderr, "unlink(%s) failed, error was (%s)\n",
- add_ldif, strerror(errno));
- if (unlink(mod_ldif))
- d_fprintf(stderr, "unlink(%s) failed, error was (%s)\n",
- mod_ldif, strerror(errno));
-
done:
- /* Close the ldif files */
+ /* Close and delete the ldif files */
if (add_fd)
fclose(add_fd);
+ if (strcmp(add_ldif, add_template) && (unlink(add_ldif))) {
+ DEBUG(1,("unlink(%s) failed, error was (%s)\n",
+ add_ldif, strerror(errno)));
+ }
+
if (mod_fd)
fclose(mod_fd);
+ if (strcmp(mod_ldif, mod_template) && (unlink(mod_ldif))) {
+ DEBUG(1,("unlink(%s) failed, error was (%s)\n",
+ mod_ldif, strerror(errno)));
+ }
+
if (ldif_fd)
fclose(ldif_fd);