also allows us to have more than 1 sync going at once (tridge) */
#include "includes.h"
+#include "../librpc/gen_ndr/svcctl.h"
+#include "nmbd/nmbd.h"
struct sync_record {
struct sync_record *next, *prev;
unstring workgroup;
unstring server;
- pstring fname;
+ char *fname;
struct in_addr ip;
pid_t pid;
};
return;
}
- if (!cli_set_port(cli, 139)) {
- return;
- }
+ cli_set_port(cli, 139);
in_addr_to_sockaddr_storage(&ss, ip);
status = cli_connect(cli, name, &ss);
if (!NT_STATUS_IS_OK(status)) {
+ cli_shutdown(cli);
return;
}
return;
}
- if (!cli_negprot(cli)) {
+ status = cli_negprot(cli);
+ if (!NT_STATUS_IS_OK(status)) {
cli_shutdown(cli);
return;
}
return;
}
- if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) {
+ if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, "IPC$", "IPC", "", 1))) {
cli_shutdown(cli);
return;
}
if (!s) goto done;
ZERO_STRUCTP(s);
-
+
unstrcpy(s->workgroup, work->work_group);
unstrcpy(s->server, name);
s->ip = ip;
- slprintf(s->fname, sizeof(pstring)-1,
- "%s/sync.%d", lp_lockdir(), counter++);
+ if (asprintf(&s->fname, "%s/sync.%d", lp_lockdir(), counter++) < 0) {
+ SAFE_FREE(s);
+ goto done;
+ }
+ /* Safe to use as 0 means no size change. */
all_string_sub(s->fname,"//", "/", 0);
-
+
DLIST_ADD(syncs, s);
/* the parent forks and returns, leaving the child to do the
fp = x_fopen(s->fname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (!fp) {
END_PROFILE(sync_browse_lists);
- _exit(1);
+ _exit(1);
}
sync_child(name, nm_type, work->work_group, ip, local, servers,
Handle one line from a completed sync file.
**********************************************************************/
-static void complete_one(struct sync_record *s,
+static void complete_one(struct sync_record *s,
char *sname, uint32 stype, char *comment)
{
struct work_record *work;
/* Create the server in the workgroup. */
create_server_on_workgroup(work, sname,stype, lp_max_ttl(), comment);
}
-
+
/**********************************************************************
Read the completed sync info.
**********************************************************************/
static void complete_sync(struct sync_record *s)
{
XFILE *f;
- unstring server, type_str;
+ char *server;
+ char *type_str;
unsigned type;
- pstring comment;
- pstring line;
+ char *comment;
+ char line[1024];
const char *ptr;
int count=0;
if (!f)
return;
-
+
while (!x_feof(f)) {
-
- if (!fgets_slash(line,sizeof(pstring),f))
+ TALLOC_CTX *frame = NULL;
+
+ if (!fgets_slash(line,sizeof(line),f))
continue;
-
+
ptr = line;
- if (!next_token(&ptr,server,NULL,sizeof(server)) ||
- !next_token(&ptr,type_str,NULL, sizeof(type_str)) ||
- !next_token(&ptr,comment,NULL, sizeof(comment))) {
+ frame = talloc_stackframe();
+ if (!next_token_talloc(frame,&ptr,&server,NULL) ||
+ !next_token_talloc(frame,&ptr,&type_str,NULL) ||
+ !next_token_talloc(frame,&ptr,&comment,NULL)) {
+ TALLOC_FREE(frame);
continue;
}
complete_one(s, server, type, comment);
count++;
+ TALLOC_FREE(frame);
}
-
x_fclose(f);
unlink(s->fname);
/* it has completed - grab the info */
complete_sync(s);
DLIST_REMOVE(syncs, s);
- ZERO_STRUCTP(s);
+ SAFE_FREE(s->fname);
SAFE_FREE(s);
}
}