summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-06-22 15:14:45 +0000
committerAndrew Tridgell <tridge@samba.org>2001-06-22 15:14:45 +0000
commit868d010aa1b614109b54928e46eb626a1d320a2d (patch)
tree7f3f13b0781a7758d8f7b7f40ef15a396dc5a0dc /source3
parent3281f6f076a13b78f3a688775993c9139526d6a3 (diff)
downloadsamba-868d010aa1b614109b54928e46eb626a1d320a2d.tar.gz
samba-868d010aa1b614109b54928e46eb626a1d320a2d.tar.bz2
samba-868d010aa1b614109b54928e46eb626a1d320a2d.zip
added the ability to test smbd safely as an ordinary user. The way it works is
that libsmb/ creates a local tcp socket then launches smbd as a subprocess attached to that socket. smbd thinks it is being launched from inetd. to use it do the following: - compile with -DSMB_REGRESSION_TEST - run like this (also works with smbtorture etc) export SMBD_TEST=1 export LIBSMB_PROG=bin/smbd smbclient //server/share -Uuser%pass obviously you need to setup a smb.conf etc. Using --prefix to configure is useful. The aim of all this stuff is to add a decent set of regression tests to the build farm, so we know if smbd actually runs correctly on all the platforms, not just builds. We can run smbtorture, masktest, locktest etc, plus a bunch of smbclient scripts and any new tests we write. This doesn't help much with nmbd (at least not yet) but its a good start. (This used to be commit 7e8e6ae9a88c4d2587eb4e7f0501cd71bd36ebb2)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/util_sec.c4
-rw-r--r--source3/lib/util_sock.c81
-rw-r--r--source3/libsmb/cliconnect.c12
-rw-r--r--source3/smbd/server.c2
4 files changed, 96 insertions, 3 deletions
diff --git a/source3/lib/util_sec.c b/source3/lib/util_sec.c
index 068be684f3..164e6ab506 100644
--- a/source3/lib/util_sec.c
+++ b/source3/lib/util_sec.c
@@ -51,11 +51,13 @@ static void assert_uid(uid_t ruid, uid_t euid)
{
if ((euid != (uid_t)-1 && geteuid() != euid) ||
(ruid != (uid_t)-1 && getuid() != ruid)) {
+#ifndef SMB_REGRESSION_TEST
DEBUG(0,("Failed to set uid privileges to (%d,%d) now set to (%d,%d)\n",
(int)ruid, (int)euid,
(int)getuid(), (int)geteuid()));
smb_panic("failed to set uid\n");
exit(1);
+#endif
}
}
@@ -66,12 +68,14 @@ static void assert_gid(gid_t rgid, gid_t egid)
{
if ((egid != (gid_t)-1 && getegid() != egid) ||
(rgid != (gid_t)-1 && getgid() != rgid)) {
+#ifndef SMB_REGRESSION_TEST
DEBUG(0,("Failed to set gid privileges to (%d,%d) now set to (%d,%d) uid=(%d,%d)\n",
(int)rgid, (int)egid,
(int)getgid(), (int)getegid(),
(int)getuid(), (int)geteuid()));
smb_panic("failed to set gid\n");
exit(1);
+#endif
}
}
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index b0426e3809..426d0572f1 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -1145,3 +1145,84 @@ int create_pipe_socket(char *dir, int dir_perms,
return s;
}
+
+#ifdef SMB_REGRESSION_TEST
+/*******************************************************************
+this is like socketpair but uses tcp. It is used by the Samba
+user testing
+ ******************************************************************/
+static int socketpair_tcp(int fd[2])
+{
+ int listener;
+ struct sockaddr sock;
+ socklen_t socklen = sizeof(sock);
+ int len = socklen;
+ int one = 1;
+ int connect_done = 0;
+
+ fd[0] = fd[1] = listener = -1;
+
+ memset(&sock, 0, sizeof(sock));
+
+ if ((listener = socket(PF_INET, SOCK_STREAM, 0)) == -1) goto failed;
+
+ setsockopt(listener,SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(one));
+
+ if (listen(listener, 1) != 0) goto failed;
+
+ if (getsockname(listener, &sock, &socklen) != 0) goto failed;
+
+ if ((fd[1] = socket(PF_INET, SOCK_STREAM, 0)) == -1) goto failed;
+
+ setsockopt(fd[1],SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(one));
+
+ set_blocking(fd[1], 0);
+
+ if (connect(fd[1],(struct sockaddr *)&sock,sizeof(sock)) == -1) {
+ if (errno != EINPROGRESS) goto failed;
+ } else {
+ connect_done = 1;
+ }
+
+ if ((fd[0] = accept(listener, &sock, &len)) == -1) goto failed;
+
+ setsockopt(fd[0],SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(one));
+
+ close(listener);
+ if (connect_done == 0) {
+ if (connect(fd[1],(struct sockaddr *)&sock,sizeof(sock)) != 0) goto failed;
+ }
+
+ set_blocking(fd[1], 1);
+
+ /* all OK! */
+ return 0;
+
+ failed:
+ if (fd[0] != -1) close(fd[0]);
+ if (fd[1] != -1) close(fd[1]);
+ if (listener != -1) close(listener);
+ return -1;
+}
+
+
+/*******************************************************************
+run a program on a local tcp socket, this is used to launch smbd
+in the test code
+ ******************************************************************/
+int sock_exec(char *prog)
+{
+ int fd[2];
+ if (socketpair_tcp(fd) != 0) return -1;
+ if (fork() == 0) {
+ close(fd[0]);
+ close(0);
+ close(1);
+ dup(fd[1]);
+ dup(fd[1]);
+ exit(system(prog));
+ }
+ close(fd[1]);
+ return fd[0];
+}
+#endif
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 529aa0fef9..034208f3b2 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -558,7 +558,6 @@ retry:
return(True);
}
-
/****************************************************************************
open the client sockets
****************************************************************************/
@@ -580,8 +579,15 @@ BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
if (cli->port == 0) cli->port = 139; /* Set to default */
- cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
- cli->port, cli->timeout);
+#ifdef SMB_REGRESSION_TEST
+ if (getenv("LIBSMB_PROG")) {
+ cli->fd = sock_exec(getenv("LIBSMB_PROG"));
+ } else
+#endif
+ {
+ cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip,
+ cli->port, cli->timeout);
+ }
if (cli->fd == -1)
return False;
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index fcee30d667..f4c82839bb 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -626,10 +626,12 @@ static void usage(char *pname)
* dump if euid != 0. Ensure this is the case.
*/
+#ifndef SMB_REGRESSION_TEST
if(geteuid() != (uid_t)0) {
fprintf(stderr, "%s: Version %s : Must have effective user id of zero to run.\n", argv[0], VERSION);
exit(1);
}
+#endif
append_log = True;