]> granicus.if.org Git - sudo/commitdiff
Move interface-related defines to interfaces.h so we don't have to include
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 17 May 1999 01:36:30 +0000 (01:36 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 17 May 1999 01:36:30 +0000 (01:36 +0000)
<netinet/in.h> everywhere.

22 files changed:
Makefile.in
check.c
check_sia.c
compat.h
find_path.c
getspwuid.c
goodpath.c
interfaces.c
interfaces.h [new file with mode: 0644]
lex.yy.c
logging.c
parse.c
parse.lex
parse.yacc
secureware.c
sudo.c
sudo.h
sudo.tab.c
sudo_setenv.c
testsudoers.c
tgetpass.c
visudo.c

index 761ab3ab47b8fef8b5fceb5915dccdebb3111fe8..ceacef970d1e85f2b97b2c6823f818ab7fe8338c 100644 (file)
@@ -110,8 +110,8 @@ TESTOBJS = interfaces.o testsudoers.o
 
 LIBOBJS = @LIBOBJS@ @ALLOCA@
 
-HDRS = sudo.h compat.h version.h insults.h \
-       ins_2001.h ins_classic.h ins_goons.h ins_csops.h sudo.tab.h
+HDRS = sudo.h compat.h version.h insults.h ins_2001.h ins_classic.h \
+       ins_goons.h ins_csops.h interfaces.h sudo.tab.h
 
 VERSION = 1.6
 
@@ -129,9 +129,9 @@ DISTFILES = $(SRCS) $(HDRS) BUGS CHANGES COPYING HISTORY INSTALL \
 
 VERSIONFILES = emul/utime.h check.c compat.h config.h.in dce_pwent.c \
               find_path.c getspwuid.c getcwd.c goodpath.c ins_2001.h \
-              ins_classic.h ins_csops.h ins_goons.h insults.h interfaces.c \
+              ins_classic.h ins_csops.h ins_goons.h insults.h interfaces.h \
               logging.c parse.c parse.lex parse.yacc pathnames.h.in \
-              putenv.c sudo.c sudo.h sudo_setenv.c testsudoers.c \
+              putenv.c sudo.c sudo.h sudo_setenv.c testsudoers.c interfaces.c \
               tgetpass.c utime.c visudo.c secureware.c check_sia.c alloc.c
 
 all: $(PROGS)
diff --git a/check.c b/check.c
index b29b2d241980c977232044987c5a55d5eb9241da..fe9d570107c00beda81c05ff73b2c493e1a88b4d 100644 (file)
--- a/check.c
+++ b/check.c
@@ -50,7 +50,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/file.h>
-#include <netinet/in.h>
 #include <pwd.h>
 #include <grp.h>
 #ifdef HAVE_KERB4
index 45f8c2681142e7b6b56a7d518a3c5a96f5536a4f..681eb6fc2d9b329c173d95c674aecb86cf68a92c 100644 (file)
@@ -45,7 +45,6 @@
 #endif /* HAVE_STRINGS_H */
 #include <sys/param.h>
 #include <sys/types.h>
-#include <netinet/in.h>
 #include <pwd.h>
 #include <siad.h>
 
index 28c90aa25d274dc58fd7e1132b58e2a3977b2c96..20dbca6e3bd5fa09877c9bf2ac00e8964edfd487 100644 (file)
--- a/compat.h
+++ b/compat.h
 #endif /* S_IRWXU */
 
 /*
- * Some OS's may not have this.
+ * In case this is not defined in <sys/types.h> or <sys/select.h>
  */
 #ifndef howmany
 #define howmany(x, y)  (((x) + ((y) - 1)) / (y))
 #endif
 
 /*
- * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
- * but that caused problems with various alternate authentication
- * methods.  So, we just define our own and assume that it is >= the
- * system max.
- */
-#define SUDO_PASS_MAX  256
-
-/*
- * Some OS's lack these
+ * These should be defined in <unistd.h> but not everyone has them.
  */
-#ifndef UID_NO_CHANGE
-#  define UID_NO_CHANGE                ((uid_t) -1)
-#endif /* UID_NO_CHANGE */
-#ifndef GID_NO_CHANGE
-#  define GID_NO_CHANGE                ((gid_t) -1)
-#endif /* GID_NO_CHANGE */
+#ifndef STDIN_FILENO
+#  define      STDIN_FILENO    0
+#endif
+#ifndef STDOUT_FILENO
+#  define      STDOUT_FILENO   1
+#endif
+#ifndef STDERR_FILENO
+#  define      STDERR_FILENO   2
+#endif
 
 /*
  * Emulate seteuid() for AIX via setuidx() -- needed for some versions of AIX
  */
 #ifndef HAVE_SETEUID
 #  ifdef __hpux
-#    define seteuid(_EUID)     (setresuid(UID_NO_CHANGE, _EUID, UID_NO_CHANGE))
+#    define seteuid(_EUID)     (setresuid((uid_t) -1, _EUID, (uid_t) -1))
 #  else
-#    define seteuid(_EUID)     (setreuid(UID_NO_CHANGE, _EUID))
+#    define seteuid(_EUID)     (setreuid((uid_t) -1, _EUID))
 #  endif /* __hpux */
 #endif /* HAVE_SETEUID */
 
index 84e81f2210376e9b86c92ef8dbbb9ba8f310153b..859706dd0b99181b2eaa2983d8381883215f5b03 100644 (file)
@@ -48,7 +48,6 @@
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/stat.h>
-#include <netinet/in.h>
 #include "sudo.h"
 
 #ifndef STDC_HEADERS
index 8ca5f6a960bdc25b1c797df36feda8f6a7add6e1..748eee30a5a3b6da263400f18587a79c57ce597b 100644 (file)
@@ -43,7 +43,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/param.h>
-#include <netinet/in.h>
 #include <pwd.h>
 #ifdef HAVE_GETSPNAM
 #  include <shadow.h>
index 93d334c4a8f5e98c10bb5acb03cac4ebeb1ffc81..6f174e055ab16c8002058eeab29814de05dde7fa 100644 (file)
@@ -45,7 +45,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/param.h>
-#include <netinet/in.h>
 
 #include "sudo.h"
 
index a6899cce7905b8983715614dda42e138219cd324..e26ecb3d1be71ffd56818ff342f631c7c8d833db 100644 (file)
 #include <net/if.h>
 
 #include "sudo.h"
-#include "version.h"
+#include "interfaces.h"
 
 #ifndef lint
 static const char rcsid[] = "$Sudo$";
 #endif /* lint */
 
-/*
- * Globals
- */
-struct interface *interfaces;
-int num_interfaces = 0;
-extern int Argc;
-extern char **Argv;
-
 
 #if defined(SIOCGIFCONF) && !defined(STUB_LOAD_INTERFACES)
 /**********************************************************************
diff --git a/interfaces.h b/interfaces.h
new file mode 100644 (file)
index 0000000..74a0c67
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  CU sudo version 1.6
+ *  Copyright (c) 1996, 1998, 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 1, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *  Please send bugs, changes, problems to sudo-bugs@courtesan.com
+ *
+ *  $Sudo$
+ */
+
+#ifndef _SUDO_INTERFACES_H
+#define _SUDO_INTERFACES_H
+
+/*
+ * IP address and netmask pairs for checking against local interfaces.
+ */
+struct interface {
+    struct in_addr addr;
+    struct in_addr netmask;
+};
+
+/*
+ * Prototypes for external functions.
+ */
+void load_interfaces   __P((void));
+
+/*
+ * Definitions for external variables.
+ */
+#ifndef MAIN
+extern struct interface *interfaces;
+extern int num_interfaces;
+#endif
+
+#endif /* _SUDO_INTERFACES_H */
index 1667083d3bd36ac1e2af0bd8ac376e1e5ba5b0dd..b9cadc8daa76128fe5f945d3d5bfd68b52ab3278 100644 (file)
--- a/lex.yy.c
+++ b/lex.yy.c
@@ -571,7 +571,6 @@ char *yytext;
 #include <ctype.h>
 #include <sys/types.h>
 #include <sys/param.h>
-#include <netinet/in.h>
 #include "sudo.h"
 #include "sudo.tab.h"
 
index 4892069afa9939d770d4b35e861826c3542ce8d6..8309365470992dd8ea792be15966ac368b3b0ec2 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -53,7 +53,6 @@
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
-#include <netinet/in.h>
 
 #include "sudo.h"
 
diff --git a/parse.c b/parse.c
index f3b64e7bc60532bbd8e1b30c0bd5631d8e0c8bd2..f18a8f867cf0a794b4b91e217b3491db42609e54 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -77,6 +77,7 @@
 #endif
 
 #include "sudo.h"
+#include "interfaces.h"
 
 #ifndef lint
 static const char rcsid[] = "$Sudo$";
index e92402b53c6a765805ba89832ce08dfc70c4da84..383a349415b7c78f8efc44e16772fd3979429187 100644 (file)
--- a/parse.lex
+++ b/parse.lex
@@ -43,7 +43,6 @@
 #include <ctype.h>
 #include <sys/types.h>
 #include <sys/param.h>
-#include <netinet/in.h>
 #include "sudo.h"
 #include "sudo.tab.h"
 
index 043dfd144d53d02348b7c4be2cd73d256dbc3c08..28a377758c1b035b8ca8d66a5cb07b6d06951341 100644 (file)
@@ -38,7 +38,6 @@
 #include <pwd.h>
 #include <sys/types.h>
 #include <sys/param.h>
-#include <netinet/in.h>
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif /* HAVE_STRING_H */
index f85ad38bb952695ea4e88260802be39e6b42fa89..af6f72c8543f3cc733d7db9f752a0731282a77fd 100644 (file)
@@ -44,7 +44,6 @@
 #endif /* HAVE_STRINGS_H */
 #include <sys/param.h>
 #include <sys/types.h>
-#include <netinet/in.h>
 #include <pwd.h>
 #ifdef __hpux
 #  include <hpsecurity.h>
diff --git a/sudo.c b/sudo.c
index b8699d6635f433981233d390b6c6898d14bfa092..3a2c9cc52eb7fac92d227736c91f8337a672c044 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -77,6 +77,7 @@
 #endif /* HAVE_KERB5 */
 
 #include "sudo.h"
+#include "interfaces.h"
 #include "version.h"
 
 #ifndef STDC_HEADERS
@@ -131,8 +132,8 @@ char *shost;
 char cwd[MAXPATHLEN];
 FILE *sudoers_fp = NULL;
 static char *runas_homedir = NULL;
-extern struct interface *interfaces;
-extern int num_interfaces;
+struct interface *interfaces;
+int num_interfaces;
 extern int printmatches;
 int arg_prompt = 0;    /* was -p used? */
 #ifdef HAVE_KERB5
@@ -869,7 +870,7 @@ check_sudoers()
            (void) fprintf(stderr, "%s: fixed mode on %s\n",
                Argv[0], _PATH_SUDO_SUDOERS);
            if (statbuf.st_gid != SUDOERS_GID) {
-               if (!chown(_PATH_SUDO_SUDOERS,GID_NO_CHANGE,SUDOERS_GID)) {
+               if (!chown(_PATH_SUDO_SUDOERS,(uid_t) -1,SUDOERS_GID)) {
                    (void) fprintf(stderr, "%s: set group on %s\n",
                        Argv[0], _PATH_SUDO_SUDOERS);
                    statbuf.st_gid = SUDOERS_GID;
diff --git a/sudo.h b/sudo.h
index 0ac1b6903193259c5a70863a35fa1bbddc475f0f..a414997db81d3bceb5bdd5786c46c74fa421b0f8 100644 (file)
--- a/sudo.h
+++ b/sudo.h
 #include <pathnames.h>
 #include "compat.h"
 
-/*
- * IP address and netmask pairs for checking against local interfaces.
- */
-struct interface {
-    struct in_addr addr;
-    struct in_addr netmask;
-};
-
 /*
  * Data structure used in parsing sudoers;
  * top of stack values are the ones that
@@ -222,6 +214,14 @@ struct generic_alias {
 #define GETPASS(p, t)          tgetpass(p, t)
 #endif
 
+/*
+ * We used to use the system definition of PASS_MAX or _PASSWD_LEN,
+ * but that caused problems with various alternate authentication
+ * methods.  So, we just define our own and assume that it is >= the
+ * system max.
+ */
+#define SUDO_PASS_MAX  256
+
 /*
  * Function prototypes
  */
@@ -235,7 +235,7 @@ int putenv          __P((const char *));
 #endif
 char *sudo_goodpath    __P((const char *));
 int sudo_setenv                __P((char *, char *));
-char *tgetpass         __P((char *, int));
+char *tgetpass         __P((const char *, int));
 int find_path          __P((char *, char **));
 void log_error         __P((int));
 void inform_user       __P((int));
@@ -243,7 +243,6 @@ void check_user             __P((void));
 int validate           __P((int));
 void set_perms         __P((int, int));
 void remove_timestamp  __P((void));
-void load_interfaces   __P((void));
 int check_secureware   __P((char *));
 void sia_attempt_auth  __P((void));
 int yyparse            __P((void));
@@ -262,8 +261,6 @@ YY_DECL;
 extern char host[];
 extern char *shost;
 extern char cwd[];
-extern struct interface *interfaces;
-extern int num_interfaces;
 extern struct passwd *user_pw_ent;
 extern char *runas_user;
 extern char *tty;
index e63b945660c54588d70b499ea6ab9c202480b051..83076666b1ed5f34dea0a25991e52395f6b44413 100644 (file)
@@ -56,7 +56,6 @@ static char yyrcsid[]
 #include <pwd.h>
 #include <sys/types.h>
 #include <sys/param.h>
-#include <netinet/in.h>
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif /* HAVE_STRING_H */
index 963cad4adea1e4f7dfaa4ce68943b6a52f0b86a9..5e6af077b2b5667d4f2c555edf9a4b115d67440f 100644 (file)
@@ -40,7 +40,6 @@
 #endif /* HAVE_UNISTD_H */
 #include <sys/types.h>
 #include <sys/param.h>
-#include <netinet/in.h>
 
 #include "sudo.h"
 
index 9d58ffbee2bbacd1cfec6257864693062481de0d..13a44d173d8b38c0e7733a2675d08b7f1b577598 100644 (file)
@@ -63,6 +63,7 @@
 #include <dirent.h>
 
 #include "sudo.h"
+#include "interfaces.h"
 
 #ifndef lint
 static const char rcsid[] = "$Sudo$";
index 1a4d6b53011fd7dc2eb69c82b3b3682672e6e689..4f4f1b9945bc099456b912a08c850e44e7842c9a 100644 (file)
@@ -67,8 +67,7 @@
 #endif /* HAVE_TERMIO_H */
 #endif /* HAVE_TERMIOS_H */
 
-#include <pathnames.h>
-#include "compat.h"
+#include "sudo.h"
 
 #ifndef TCSASOFT
 #define TCSASOFT       0
@@ -108,8 +107,7 @@ tgetpass(prompt, timeout)
 #else
     int oldmask;
 #endif /* POSIX_SIGNALS */
-    int n, echo;
-    FILE *input, *output;
+    int n, echo, input, output;
     static char buf[SUDO_PASS_MAX + 1];
     fd_set *readfds;
     struct timeval tv;
@@ -130,45 +128,36 @@ tgetpass(prompt, timeout)
      * open /dev/tty for reading/writing if possible or use
      * stdin and stderr instead.
      */
-    if ((input = fopen(_PATH_TTY, "r+")) == NULL) {
-       input = stdin;
-       output = stderr;
-    } else {
-       output = input;
-       setbuf(output, NULL);
+    if ((input = output = open(_PATH_TTY, O_RDWR)) == NULL) {
+       input = STDIN_FILENO;
+       output = STDERR_FILENO;
     }
 
     /* print the prompt */
     if (prompt)
-       fputs(prompt, output);
-
-    /* rewind if necessary */
-    if (input == output) {
-       (void) fflush(output);
-       (void) rewind(output);
-    }
+       (void) write(output, prompt, strlen(prompt) + 1);
 
     /*
      * turn off echo
      */
 #ifdef HAVE_TERMIOS_H
-    (void) tcgetattr(fileno(input), &term);
+    (void) tcgetattr(input, &term);
     if ((echo = (term.c_lflag & ECHO))) {
        term.c_lflag &= ~ECHO;
-       (void) tcsetattr(fileno(input), TCSAFLUSH|TCSASOFT, &term);
+       (void) tcsetattr(input, TCSAFLUSH|TCSASOFT, &term);
     }
 #else
 #ifdef HAVE_TERMIO_H
-    (void) ioctl(fileno(input), TCGETA, &term);
+    (void) ioctl(input, TCGETA, &term);
     if ((echo = (term.c_lflag & ECHO))) {
        term.c_lflag &= ~ECHO;
-       (void) ioctl(fileno(input), TCSETA, &term);
+       (void) ioctl(input, TCSETA, &term);
     }
 #else
-    (void) ioctl(fileno(input), TIOCGETP, &ttyb);
+    (void) ioctl(input, TIOCGETP, &ttyb);
     if ((echo = (ttyb.sg_flags & ECHO))) {
        ttyb.sg_flags &= ~ECHO;
-       (void) ioctl(fileno(input), TIOCSETP, &ttyb);
+       (void) ioctl(input, TIOCSETP, &ttyb);
     }
 #endif /* HAVE_TERMIO_H */
 #endif /* HAVE_TERMIOS_H */
@@ -178,14 +167,10 @@ tgetpass(prompt, timeout)
      */
     if (timeout > 0) {
        /* setup for select(2) */
-       n = howmany(fileno(input) + 1, NFDBITS) * sizeof(fd_mask);
-       if ((readfds = (fd_set *) malloc(n)) == NULL) {
-           (void) fprintf(stderr, "Cannot allocate memory: ");
-           perror("");
-           return(NULL);
-       }
+       n = howmany(input + 1, NFDBITS) * sizeof(fd_mask);
+       readfds = (fd_set *) emalloc(n);
        (void) memset((VOID *)readfds, 0, n);
-       FD_SET(fileno(input), readfds);
+       FD_SET(input, readfds);
 
        /* set timeout for select */
        tv.tv_sec = timeout;
@@ -195,21 +180,21 @@ tgetpass(prompt, timeout)
         * get password or return empty string if nothing to read by timeout
         */
        buf[0] = '\0';
-       while ((n = select(fileno(input) + 1, readfds, 0, 0, &tv)) == -1 &&
+       while ((n = select(input + 1, readfds, 0, 0, &tv)) == -1 &&
            errno == EINTR)
            ;
-       if (n != 0 && fgets(buf, sizeof(buf), input)) {
-           n = strlen(buf);
+       if (n != 0 && (n = read(input, buf, sizeof(buf) - 1)) > 0) {
            if (buf[n - 1] == '\n')
-               buf[n - 1] = '\0';
+               n--;
+           buf[n] = '\0';
        }
        free(readfds);
     } else {
        buf[0] = '\0';
-       if (fgets(buf, sizeof(buf), input)) {
-           n = strlen(buf);
+       if ((n = read(input, buf, sizeof(buf) - 1)) > 0) {
            if (buf[n - 1] == '\n')
-               buf[n - 1] = '\0';
+               n--;
+           buf[n] = '\0';
        }
     }
 
@@ -217,30 +202,24 @@ tgetpass(prompt, timeout)
 #ifdef HAVE_TERMIOS_H
     if (echo) {
        term.c_lflag |= ECHO;
-       (void) tcsetattr(fileno(input), TCSAFLUSH|TCSASOFT, &term);
+       (void) tcsetattr(input, TCSAFLUSH|TCSASOFT, &term);
     }
 #else
 #ifdef HAVE_TERMIO_H
     if (echo) {
        term.c_lflag |= ECHO;
-       (void) ioctl(fileno(input), TCSETA, &term);
+       (void) ioctl(input, TCSETA, &term);
     }
 #else
     if (echo) {
        ttyb.sg_flags |= ECHO;
-       (void) ioctl(fileno(input), TIOCSETP, &ttyb);
+       (void) ioctl(input, TIOCSETP, &ttyb);
     }
 #endif /* HAVE_TERMIO_H */
 #endif /* HAVE_TERMIOS_H */
 
-    /* rewind if necessary */
-    if (input == output) {
-       (void) fflush(output);
-       (void) rewind(output);
-    }
-
     /* print a newline since echo is turned off */
-    (void) fputc('\n', output);
+    (void) write(output, "\n", 1);
 
     /* restore old signal mask */
 #ifdef POSIX_SIGNALS
@@ -250,8 +229,8 @@ tgetpass(prompt, timeout)
 #endif
 
     /* close /dev/tty if that's what we opened */
-    if (input != stdin)
-       (void) fclose(input);
+    if (input != STDIN_FILENO)
+       (void) close(input);
 
     return(buf);
 }
index b7d309aa0b04b9bf67710663b47b9442433c2f78..813a8228de9ed3fbbd0232ddea188f980a7a886c 100644 (file)
--- a/visudo.c
+++ b/visudo.c
@@ -53,7 +53,6 @@
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/file.h>
-#include <netinet/in.h>
 
 #include "sudo.h"
 #include "version.h"