summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h14
-rw-r--r--source3/include/vagent.h4
-rw-r--r--source3/lib/util_sock.c62
-rw-r--r--source3/utils/nmb-agent.c54
-rw-r--r--source3/utils/smb-agent.c45
5 files changed, 77 insertions, 102 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 5e423e3726..0cea6792c6 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -138,12 +138,6 @@ BOOL allow_access(char *deny_list,char *allow_list,
char *cname,char *caddr);
BOOL check_access(int sock, char *allow_list, char *deny_list);
-/*The following definitions come from lib/agent.c */
-
-void init_sock_redir(struct vagent_ops*va);
-void free_sock_redir(struct vagent_ops*va);
-void start_agent(struct vagent_ops *va);
-
/*The following definitions come from lib/bitmap.c */
struct bitmap *bitmap_allocate(int n);
@@ -620,6 +614,8 @@ void reset_globals_after_fork(void);
char *client_name(int fd);
char *client_addr(int fd);
int open_pipe_sock(char *path);
+int create_pipe_socket(char *dir, int dir_perms,
+ char *path, int path_perms);
/*The following definitions come from lib/util_status.c */
@@ -681,6 +677,12 @@ BOOL copy_unistr2(UNISTR2 *str, const UNISTR2 *from);
UNISTR2 *unistr2_dup(const UNISTR2 *name);
void unistr2_free(UNISTR2 *name);
+/*The following definitions come from lib/vagent.c */
+
+void init_sock_redir(struct vagent_ops*va);
+void free_sock_redir(struct vagent_ops*va);
+void start_agent(struct vagent_ops *va);
+
/*The following definitions come from libsmb/clientgen.c */
void copy_user_creds(struct user_credentials *to,
diff --git a/source3/include/vagent.h b/source3/include/vagent.h
index 19bb976635..c8b85181e4 100644
--- a/source3/include/vagent.h
+++ b/source3/include/vagent.h
@@ -36,14 +36,14 @@ struct sock_redir
struct vagent_ops
{
void (*free_sock)(void* sock);
- int (*get_agent_sock)(void* id);
+ int (*get_agent_sock)(char* id);
BOOL (*process_cli_sock)(struct sock_redir **socks, uint32 num_socks,
struct sock_redir *sock);
BOOL (*process_srv_sock)(struct sock_redir **socks, uint32 num_socks,
int fd);
- void* id;
+ char* id;
struct sock_redir **socks;
uint32 num_socks;
};
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index c0ca723e38..71e51d2771 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -894,3 +894,65 @@ int open_pipe_sock(char *path)
return sock;
}
+
+int create_pipe_socket(char *dir, int dir_perms,
+ char *path, int path_perms)
+{
+ int s;
+ struct sockaddr_un sa;
+
+ mkdir(dir, dir_perms);
+
+ if (chmod(dir, dir_perms) < 0)
+ {
+ DEBUG(0, ("chmod on %s failed\n", dir));
+ return -1;
+ }
+
+ if (!remove(path))
+ {
+ DEBUG(0, ("remove on %s failed\n", path));
+ return -1;
+ }
+
+ /* start listening on unix socket */
+ s = socket(AF_UNIX, SOCK_STREAM, 0);
+
+ if (s < 0)
+ {
+ DEBUG(0, ("socket open failed\n"));
+ return -1;
+ }
+
+ ZERO_STRUCT(sa);
+ sa.sun_family = AF_UNIX;
+ safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1);
+
+ if (bind(s, (struct sockaddr*) &sa, sizeof(sa)) < 0)
+ {
+ DEBUG(0, ("socket bind to %s failed\n", sa.sun_path));
+ close(s);
+ remove(path);
+ return -1;
+ }
+
+ if (s == -1)
+ {
+ DEBUG(0,("bind failed\n"));
+ remove(path);
+ return -1;
+ }
+
+ if (path_perms != 0)
+ {
+ chmod(path, path_perms);
+ }
+
+ if (listen(s, 5) == -1)
+ {
+ DEBUG(0,("listen failed\n"));
+ return -1;
+ }
+
+ return s;
+}
diff --git a/source3/utils/nmb-agent.c b/source3/utils/nmb-agent.c
index ad9c958350..f49983db79 100644
--- a/source3/utils/nmb-agent.c
+++ b/source3/utils/nmb-agent.c
@@ -167,63 +167,15 @@ static BOOL process_srv_sock(struct sock_redir **socks,
return True;
}
-static int get_agent_sock(void*id)
+static int get_agent_sock(char *id)
{
- int s;
- struct sockaddr_un sa;
- fstring path;
fstring dir;
-
- CatchChild();
+ fstring path;
slprintf(dir, sizeof(dir)-1, "/tmp/.nmb");
- mkdir(dir, 0777);
-
slprintf(path, sizeof(path)-1, "%s/agent", dir);
- if (chmod(dir, 0777) < 0)
- {
- fprintf(stderr, "chmod on %s failed\n", sa.sun_path);
- return -1;
- }
-
-
- /* start listening on unix socket */
- s = socket(AF_UNIX, SOCK_STREAM, 0);
-
- if (s < 0)
- {
- fprintf(stderr, "socket open failed\n");
- return -1;
- }
-
- ZERO_STRUCT(sa);
- sa.sun_family = AF_UNIX;
- safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1);
-
- if (bind(s, (struct sockaddr*) &sa, sizeof(sa)) < 0)
- {
- fprintf(stderr, "socket bind to %s failed\n", sa.sun_path);
- close(s);
- remove(path);
- return -1;
- }
-
- if (s == -1)
- {
- DEBUG(0,("bind failed\n"));
- remove(path);
- return -1;
- }
-
- chmod(path, 0777);
-
- if (listen(s, 5) == -1)
- {
- DEBUG(0,("listen failed\n"));
- return -1;
- }
- return s;
+ return create_pipe_socket(dir, 0777, path, 0777);
}
static void start_nmb_agent(void)
diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c
index 5d1aa4db04..96c43cadaf 100644
--- a/source3/utils/smb-agent.c
+++ b/source3/utils/smb-agent.c
@@ -303,7 +303,7 @@ static BOOL process_srv_sock(struct sock_redir **socks, uint32 num_socks,
return False;
}
-static int get_agent_sock(void *id)
+static int get_agent_sock(char *id)
{
int s;
struct sockaddr_un sa;
@@ -311,50 +311,9 @@ static int get_agent_sock(void *id)
fstring dir;
slprintf(dir, sizeof(dir)-1, "/tmp/.smb.%d", getuid());
- mkdir(dir, S_IRUSR|S_IWUSR|S_IXUSR);
-
slprintf(path, sizeof(path)-1, "%s/agent", dir);
- if (chmod(dir, S_IRUSR|S_IWUSR|S_IXUSR) < 0)
- {
- fprintf(stderr, "chmod on %s failed\n", sa.sun_path);
- exit(1);
- }
-
-
- /* start listening on unix socket */
- s = socket(AF_UNIX, SOCK_STREAM, 0);
-
- if (s < 0)
- {
- fprintf(stderr, "socket open failed\n");
- exit(1);
- }
-
- ZERO_STRUCT(sa);
- sa.sun_family = AF_UNIX;
- safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1);
- if (bind(s, (struct sockaddr*) &sa, sizeof(sa)) < 0)
- {
- fprintf(stderr, "socket bind to %s failed\n", sa.sun_path);
- close(s);
- remove(path);
- exit(1);
- }
-
- if (s == -1)
- {
- DEBUG(0,("bind failed\n"));
- remove(path);
- exit(1);
- }
-
- if (listen(s, 5) == -1)
- {
- DEBUG(0,("listen failed\n"));
- remove(path);
- }
- return s;
+ return create_pipe_socket(dir, S_IRUSR|S_IWUSR|S_IXUSR, path, 0);
}
static void start_smb_agent(void)