]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
created create_pipe_socket() function.
authorLuke Leighton <lkcl@samba.org>
Sun, 5 Dec 1999 00:13:17 +0000 (00:13 +0000)
committerLuke Leighton <lkcl@samba.org>
Sun, 5 Dec 1999 00:13:17 +0000 (00:13 +0000)
(This used to be commit a3af3b4312144943413894b18b5845b56474ebb5)

source3/include/proto.h
source3/include/vagent.h
source3/lib/util_sock.c
source3/utils/nmb-agent.c
source3/utils/smb-agent.c

index 5e423e37266aa6f2b3a7d0982be9c720c49c2fad..0cea6792c687877e2a03e3ec62922958b0be898c 100644 (file)
@@ -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,
index 19bb976635461f9779a9bdebd130ba3abca305df..c8b85181e4e4dbad9b61834e47d8cf4c41002b26 100644 (file)
@@ -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;
 };
index c0ca723e3893012b85fee0c2b57ecdd22b72faff..71e51d2771b60caa419b8f1fb5c4af19c8850eaa 100644 (file)
@@ -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;
+}
index ad9c958350ec3ffb3b7cc5ce1c1e23bf3b9bc4db..f49983db79cdd37a1343dde7a7769103d64e5934 100644 (file)
@@ -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)
index 5d1aa4db0469079cd36c612c03731e0ce1e84552..96c43cadaf45f648c16c373ec8b9053acc673e20 100644 (file)
@@ -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)