summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-12-03 19:55:34 +0000
committerLuke Leighton <lkcl@samba.org>1999-12-03 19:55:34 +0000
commit6eebe18fa9682f570127b08fb116ab561223de22 (patch)
treefb47ba04b4543590269c8cda39585a00eb26eace
parent7d01f964ff3c1a11bd72d987312f9826fee1c124 (diff)
downloadsamba-6eebe18fa9682f570127b08fb116ab561223de22.tar.gz
samba-6eebe18fa9682f570127b08fb116ab561223de22.tar.bz2
samba-6eebe18fa9682f570127b08fb116ab561223de22.zip
smb-agent improvements. added -D (daemon) option. smb agent is
restricted to connections from the current user (socket is created with current user uid). (This used to be commit 5af076e4b7ee13eebe0b89748e3f5a1ef21f8c73)
-rw-r--r--source3/libsmb/clientgen.c6
-rw-r--r--source3/utils/smb-agent.c88
2 files changed, 76 insertions, 18 deletions
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index 218ab67758..176be9948b 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -2938,6 +2938,7 @@ static int cli_init_redirect(struct cli_state *cli,
struct sockaddr_un sa;
fstring ip_name;
struct cli_state cli_redir;
+ fstring path;
pstring data;
uint32 len;
@@ -2945,6 +2946,8 @@ static int cli_init_redirect(struct cli_state *cli,
char *in = cli->inbuf;
char *out = cli->outbuf;
+ slprintf(path, sizeof(path)-1, "/tmp/smb-agent/smb.%d", getuid());
+
if (strequal(srv_name, "*SMBSERVER"))
{
fstrcpy(ip_name, "\\\\");
@@ -2962,8 +2965,7 @@ static int cli_init_redirect(struct cli_state *cli,
ZERO_STRUCT(sa);
sa.sun_family = AF_UNIX;
- safe_strcpy(sa.sun_path, "/tmp/smb-agent/smb.sock",
- sizeof(sa.sun_path)-1);
+ safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1);
DEBUG(10, ("socket open succeeded. file name: %s\n", sa.sun_path));
diff --git a/source3/utils/smb-agent.c b/source3/utils/smb-agent.c
index 52feda2bea..8c039dfc86 100644
--- a/source3/utils/smb-agent.c
+++ b/source3/utils/smb-agent.c
@@ -218,11 +218,15 @@ static void agent_child(int c)
DEBUG(0,("client closed connection\n"));
exit(0);
}
- if (!send_smb(s->fd, packet))
+ /* ignore keep-alives */
+ if (CVAL(packet, 0) != 0x85)
{
- DEBUG(0,("server is dead\n"));
- exit(1);
- }
+ if (!send_smb(s->fd, packet))
+ {
+ DEBUG(0,("server is dead\n"));
+ exit(1);
+ }
+ }
}
}
if (s != NULL && FD_ISSET(s->fd, &fds))
@@ -258,12 +262,14 @@ static void start_agent(void)
{
int s, c;
struct sockaddr_un sa;
+ fstring path;
+ slprintf(path, sizeof(path)-1, "/tmp/smb-agent/smb.%d", getuid());
CatchChild();
/* start listening on unix socket */
-
- mkdir("/tmp/smb-agent", 700);
+ mkdir("/tmp/smb-agent", 777);
+
s = socket(AF_UNIX, SOCK_STREAM, 0);
if (s < 0)
@@ -274,27 +280,35 @@ static void start_agent(void)
ZERO_STRUCT(sa);
sa.sun_family = AF_UNIX;
- safe_strcpy(sa.sun_path, "/tmp/smb-agent/smb.sock",
- sizeof(sa.sun_path)-1);
+ 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("/tmp/smb-agent/smb.sock");
+ remove(path);
+ exit(1);
+ }
+
+ if (chmod(path, S_IRUSR|S_IWUSR|S_ISVTX) < 0)
+ {
+ fprintf(stderr, "chmod on %s failed\n", sa.sun_path);
+ close(s);
+ remove(path);
exit(1);
}
- if (s == -1) {
+ if (s == -1)
+ {
DEBUG(0,("bind failed\n"));
- remove("/tmp/smb-agent/smb.sock");
+ remove(path);
exit(1);
}
if (listen(s, 5) == -1)
{
DEBUG(0,("listen failed\n"));
- remove("/tmp/smb-agent/smb.sock");
+ remove(path);
}
while (1)
@@ -325,23 +339,65 @@ static void start_agent(void)
}
}
+/****************************************************************************
+usage on the program
+****************************************************************************/
+static void usage(char *pname)
+{
+ printf("Usage: %s [-D]", pname);
+
+ printf("\nVersion %s\n",VERSION);
+ printf("\t-D run as a daemon\n");
+ printf("\t-h usage\n");
+ printf("\n");
+}
int main(int argc, char *argv[])
{
pstring configfile;
+ BOOL is_daemon = False;
+ int opt;
+ extern pstring debugf;
TimeInit();
- setup_logging(argv[0],True);
+ pstrcpy(configfile,CONFIGFILE);
+
+ while ((opt = getopt(argc, argv, "Dh")) != EOF)
+ {
+ switch (opt)
+ {
+ case 'D':
+ {
+ is_daemon = True;
+ break;
+ }
+ case 'h':
+ default:
+ {
+ usage(argv[0]);
+ break;
+ }
+ }
+ }
+
+ slprintf(debugf, sizeof(debugf)-1, "log.%s", argv[0]);
+ setup_logging(argv[0], !is_daemon);
charset_initialise();
- pstrcpy(configfile,CONFIGFILE);
-
- if (!lp_load(configfile,True,False,False)) {
+ if (!lp_load(configfile,True,False,False))
+ {
DEBUG(0,("Unable to load config file\n"));
}
+ if (is_daemon)
+ {
+ DEBUG(0,("%s: becoming daemon\n", argv[0]));
+ become_daemon();
+ }
+
start_agent();
+
return 0;
}