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);
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 */
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,
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;
};
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;
+}
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)
return False;
}
-static int get_agent_sock(void *id)
+static int get_agent_sock(char *id)
{
int s;
struct sockaddr_un sa;
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)