- make the regresison test mode code build in by default. This should
authorAndrew Tridgell <tridge@samba.org>
Mon, 25 Jun 2001 00:46:34 +0000 (00:46 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 25 Jun 2001 00:46:34 +0000 (00:46 +0000)
  allow us to have test targets without special configure options
- fixed make proto so that it actually does something
(This used to be commit 55109a752578e9389d853cb27ec17c2114ecff77)

source3/Makefile.in
source3/lib/util_sec.c
source3/lib/util_sock.c
source3/libsmb/cliconnect.c
source3/smbd/server.c

index bf13115445c4599c3e372620f3d04e06d843a493..6f2334a0686587ead813b2d444f6e1f3dcd82130 100644 (file)
@@ -709,11 +709,14 @@ winbindd_proto:
          -h _WINBINDD_PROTO_H_ nsswitch/winbindd_proto.h \
          $(WINBINDD_OBJ1)
 
+delproto:
+       @/bin/rm -f include/proto.h
+
 include/proto.h: 
        @echo rebuilding include/proto.h
        @cd $(srcdir) && $(AWK) -f script/mkproto.awk `echo $(PROTO_OBJ) | tr ' ' '\n' | sed -e 's/\.o/\.c/g' | sort -u | egrep -v 'ubiqx/|wrapped'` > include/proto.h
 
-proto: include/proto.h
+proto: delproto include/proto.h
 
 etags:
        etags `find $(srcdir) -name "*.[ch]" | grep -v /CVS/`
index 164e6ab506e5fcc2f785617ccbfe33b28e09d50f..c62df8239652fd8f9392e427b8e4ea4d0cd4ad55 100644 (file)
@@ -44,6 +44,31 @@ extern int DEBUGLEVEL;
 #define smb_panic(x) exit(1)
 #endif
 
+/* are we running as non-root? This is used by the regresison test code,
+   and potentially also for sites that want non-root smbd */
+static uid_t initial_uid;
+
+/****************************************************************************
+remember what uid we got started as - this allows us to run correctly
+as non-root while catching trapdoor systems
+****************************************************************************/
+void sec_init(void)
+{
+       initial_uid = geteuid();
+       if (initial_uid != (uid_t)0) {
+               /* the DEBUG() subsystem has not been initialised when this is called */
+               fprintf(stderr, "WARNING: running as non-root. Some functionality will be missing\n");
+       }
+}
+
+/****************************************************************************
+are we running in non-root mode?
+****************************************************************************/
+BOOL non_root_mode(void)
+{
+       return (initial_uid != (uid_t)0);
+}
+
 /****************************************************************************
 abort if we haven't set the uid correctly
 ****************************************************************************/
@@ -51,13 +76,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
+               if (!non_root_mode()) {
+                       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);
+               }
        }
 }
 
@@ -68,14 +93,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
+               if (!non_root_mode()) {
+                       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);
+               }
        }
 }
 
index 426d0572f120c01a3e2eac15f5a41e17ed6f0c03..7f8b83ec7d3b8722fa6b3417ec40f14adc614e9d 100644 (file)
@@ -1146,36 +1146,33 @@ 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 
+regression test code
+The function guarantees that nobody else can attach to the socket,
+or if they do that this function fails and the socket gets closed
+returns 0 on success, -1 on failure
+the resulting file descriptors are symmetrical
  ******************************************************************/
 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) {
@@ -1184,9 +1181,7 @@ static int socketpair_tcp(int fd[2])
                connect_done = 1;
        }
 
-       if ((fd[0] = accept(listener, &sock, &len)) == -1) goto failed;
-
-       setsockopt(fd[0],SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(one));
+       if ((fd[0] = accept(listener, &sock, &socklen)) == -1) goto failed;
 
        close(listener);
        if (connect_done == 0) {
@@ -1208,9 +1203,12 @@ static int socketpair_tcp(int fd[2])
 
 /*******************************************************************
 run a program on a local tcp socket, this is used to launch smbd
-in the test code
+when regression testing
+the return value is a socket which is attached to a subprocess
+running "prog". stdin and stdout are attached. stderr is left
+attached to the original stderr
  ******************************************************************/
-int sock_exec(char *prog)
+int sock_exec(const char *prog)
 {
        int fd[2];
        if (socketpair_tcp(fd) != 0) return -1;
@@ -1225,4 +1223,4 @@ int sock_exec(char *prog)
        close(fd[1]);
        return fd[0];
 }
-#endif
+
index 034208f3b24e4aba4597caa746e6ecba465328f0..67eef52583f169d5bafccd3a69b1300160b510c7 100644 (file)
@@ -579,12 +579,9 @@ BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
 
         if (cli->port == 0) cli->port = 139;  /* Set to default */
 
-#ifdef SMB_REGRESSION_TEST
        if (getenv("LIBSMB_PROG")) {
                cli->fd = sock_exec(getenv("LIBSMB_PROG"));
-       } else 
-#endif
-       {
+       } else {
                cli->fd = open_socket_out(SOCK_STREAM, &cli->dest_ip, 
                                          cli->port, cli->timeout);
        }
index f4c82839bb11f9473ebc523169b637b87aa10cfd..17b7774b1db6c6f3f0d8da91a5901279d07d45d0 100644 (file)
@@ -621,17 +621,7 @@ static void usage(char *pname)
        setluid(0);
 #endif
 
-       /*
-        * gain_root_privilege uses an assert than will cause a core
-        * 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
+       sec_init();
 
        append_log = True;