mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-31 11:30:56 +08:00
* Makefile.in (DLL_OFILES): Add getopt.o and iruserok.o.
* cygwin.din: Export __check_rhosts_file, __rcmd_errstr, optarg, opterr, optind, optopt, optreset, getopt, getopt_long, iruserok and ruserok. * getopt.c: Moved from lib to here. Define opt* variables as dllexport. * iruserok.c: Moved from lib to here. Rearrange function order. Prefer using 64/32 bit functions. * syscalls.cc (shell_fp): Define as struct __sFILE64. (getusershell): Use fopen64 instead of fopen. * winsup.h: Add declarations for seteuid32, fopen64, cygwin_gethostbyname and cygwin_inet_addr. * include/getopt.h: Declare opt* variables dllimport. * include/cygwin/version.h: Bump API minor number.
This commit is contained in:
parent
6d2d2bce72
commit
932a40e86b
@ -1,3 +1,20 @@
|
|||||||
|
2003-09-10 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* Makefile.in (DLL_OFILES): Add getopt.o and iruserok.o.
|
||||||
|
* cygwin.din: Export __check_rhosts_file, __rcmd_errstr, optarg,
|
||||||
|
opterr, optind, optopt, optreset, getopt, getopt_long, iruserok
|
||||||
|
and ruserok.
|
||||||
|
* getopt.c: Moved from lib to here. Define opt* variables as
|
||||||
|
dllexport.
|
||||||
|
* iruserok.c: Moved from lib to here. Rearrange function order.
|
||||||
|
Prefer using 64/32 bit functions.
|
||||||
|
* syscalls.cc (shell_fp): Define as struct __sFILE64.
|
||||||
|
(getusershell): Use fopen64 instead of fopen.
|
||||||
|
* winsup.h: Add declarations for seteuid32, fopen64,
|
||||||
|
cygwin_gethostbyname and cygwin_inet_addr.
|
||||||
|
* include/getopt.h: Declare opt* variables dllimport.
|
||||||
|
* include/cygwin/version.h: Bump API minor number.
|
||||||
|
|
||||||
2003-09-10 Christopher Faylor <cgf@redhat.com>
|
2003-09-10 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* exceptions.cc (sig_handle_tty_stop): Check parent PID_NOCLDSTOP
|
* exceptions.cc (sig_handle_tty_stop): Check parent PID_NOCLDSTOP
|
||||||
|
@ -146,7 +146,7 @@ MALLOC_OFILES=@MALLOC_OFILES@
|
|||||||
DLL_IMPORTS:=$(w32api_lib)/libkernel32.a
|
DLL_IMPORTS:=$(w32api_lib)/libkernel32.a
|
||||||
|
|
||||||
# Please maintain this list in sorted order, with maximum files per 80 col line
|
# Please maintain this list in sorted order, with maximum files per 80 col line
|
||||||
DLL_OFILES:=assert.o autoload.o cxx.o bsdlib.o cygheap.o cygthread.o dcrt0.o \
|
DLL_OFILES:=assert.o autoload.o bsdlib.o cxx.o cygheap.o cygthread.o dcrt0.o \
|
||||||
debug.o delqueue.o dir.o dlfcn.o dll_init.o dtable.o environ.o \
|
debug.o delqueue.o dir.o dlfcn.o dll_init.o dtable.o environ.o \
|
||||||
errno.o exceptions.o exec.o external.o fcntl.o fhandler.o \
|
errno.o exceptions.o exec.o external.o fcntl.o fhandler.o \
|
||||||
fhandler_clipboard.o fhandler_console.o fhandler_disk_file.o \
|
fhandler_clipboard.o fhandler_console.o fhandler_disk_file.o \
|
||||||
@ -155,15 +155,15 @@ DLL_OFILES:=assert.o autoload.o cxx.o bsdlib.o cygheap.o cygthread.o dcrt0.o \
|
|||||||
fhandler_raw.o fhandler_registry.o fhandler_serial.o \
|
fhandler_raw.o fhandler_registry.o fhandler_serial.o \
|
||||||
fhandler_socket.o fhandler_tape.o fhandler_termios.o \
|
fhandler_socket.o fhandler_tape.o fhandler_termios.o \
|
||||||
fhandler_tty.o fhandler_virtual.o fhandler_windows.o \
|
fhandler_tty.o fhandler_virtual.o fhandler_windows.o \
|
||||||
fhandler_zero.o fnmatch.o fork.o glob.o grp.o heap.o init.o ioctl.o \
|
fhandler_zero.o fnmatch.o fork.o getopt.o glob.o grp.o heap.o init.o \
|
||||||
ipc.o localtime.o malloc_wrapper.o miscfuncs.o mmap.o msg.o \
|
ioctl.o ipc.o iruserok.o localtime.o malloc_wrapper.o miscfuncs.o \
|
||||||
net.o netdb.o ntea.o passwd.o path.o pinfo.o pipe.o poll.o pthread.o \
|
mmap.o msg.o net.o netdb.o ntea.o passwd.o path.o pinfo.o pipe.o \
|
||||||
regcomp.o regerror.o regexec.o regfree.o registry.o resource.o \
|
poll.o pthread.o regcomp.o regerror.o regexec.o regfree.o registry.o \
|
||||||
scandir.o sched.o sec_acl.o sec_helper.o security.o select.o sem.o \
|
resource.o scandir.o sched.o sec_acl.o sec_helper.o security.o \
|
||||||
shared.o shm.o signal.o sigproc.o smallprint.o spawn.o strace.o \
|
select.o sem.o shared.o shm.o signal.o sigproc.o smallprint.o spawn.o \
|
||||||
strsep.o sync.o syscalls.o sysconf.o syslog.o termios.o thread.o \
|
strace.o strsep.o sync.o syscalls.o sysconf.o syslog.o termios.o \
|
||||||
times.o tty.o uinfo.o uname.o v8_regexp.o v8_regerror.o v8_regsub.o \
|
thread.o times.o tty.o uinfo.o uname.o v8_regexp.o v8_regerror.o \
|
||||||
wait.o wincap.o window.o \
|
v8_regsub.o wait.o wincap.o window.o \
|
||||||
$(EXTRA_DLL_OFILES) $(EXTRA_OFILES) $(MALLOC_OFILES) $(MT_SAFE_OBJECTS)
|
$(EXTRA_DLL_OFILES) $(EXTRA_OFILES) $(MALLOC_OFILES) $(MT_SAFE_OBJECTS)
|
||||||
|
|
||||||
GMON_OFILES:=gmon.o mcount.o profil.o
|
GMON_OFILES:=gmon.o mcount.o profil.o
|
||||||
|
@ -3,10 +3,12 @@ LIBRARY "cygwin1.dll" BASE=0x61000000
|
|||||||
EXPORTS
|
EXPORTS
|
||||||
__argc DATA
|
__argc DATA
|
||||||
__argv DATA
|
__argv DATA
|
||||||
|
__check_rhosts_file DATA
|
||||||
__cygwin_environ DATA
|
__cygwin_environ DATA
|
||||||
__cygwin_user_data DATA
|
__cygwin_user_data DATA
|
||||||
__mb_cur_max DATA
|
__mb_cur_max DATA
|
||||||
__progname DATA
|
__progname DATA
|
||||||
|
__rcmd_errstr DATA
|
||||||
_check_for_executable DATA
|
_check_for_executable DATA
|
||||||
_ctype_ DATA
|
_ctype_ DATA
|
||||||
_daylight DATA
|
_daylight DATA
|
||||||
@ -17,6 +19,11 @@ sys_nerr = _sys_nerr DATA
|
|||||||
_timezone DATA
|
_timezone DATA
|
||||||
_tzname DATA
|
_tzname DATA
|
||||||
h_errno DATA
|
h_errno DATA
|
||||||
|
optarg DATA
|
||||||
|
opterr DATA
|
||||||
|
optind DATA
|
||||||
|
optopt DATA
|
||||||
|
optreset DATA
|
||||||
reent_data DATA
|
reent_data DATA
|
||||||
@ALLOCA@
|
@ALLOCA@
|
||||||
@DEF_DLL_ENTRY@
|
@DEF_DLL_ENTRY@
|
||||||
@ -617,6 +624,8 @@ getmntent
|
|||||||
_getmntent = getmntent
|
_getmntent = getmntent
|
||||||
getmode
|
getmode
|
||||||
_getmode = getmode
|
_getmode = getmode
|
||||||
|
getopt
|
||||||
|
getopt_long
|
||||||
getpagesize
|
getpagesize
|
||||||
_getpagesize = getpagesize
|
_getpagesize = getpagesize
|
||||||
getpass
|
getpass
|
||||||
@ -704,6 +713,8 @@ ioctl
|
|||||||
_ioctl = ioctl
|
_ioctl = ioctl
|
||||||
iprintf
|
iprintf
|
||||||
_iprintf = iprintf
|
_iprintf = iprintf
|
||||||
|
iruserok
|
||||||
|
ruserok
|
||||||
isalnum
|
isalnum
|
||||||
_isalnum = isalnum
|
_isalnum = isalnum
|
||||||
isalpha
|
isalpha
|
||||||
|
@ -217,13 +217,15 @@ details. */
|
|||||||
92: Export getusershell, setusershell, endusershell
|
92: Export getusershell, setusershell, endusershell
|
||||||
93: Export daemon, forkpty, openpty, iruserok, ruserok, login_tty,
|
93: Export daemon, forkpty, openpty, iruserok, ruserok, login_tty,
|
||||||
openpty, forkpty, revoke, logwtmp, updwtmp
|
openpty, forkpty, revoke, logwtmp, updwtmp
|
||||||
|
94: Export getopt, getopt_long, optarg, opterr, optind, optopt,
|
||||||
|
optreset, __check_rhosts_file, __rcmd_errstr.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
|
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
|
||||||
|
|
||||||
#define CYGWIN_VERSION_API_MAJOR 0
|
#define CYGWIN_VERSION_API_MAJOR 0
|
||||||
#define CYGWIN_VERSION_API_MINOR 93
|
#define CYGWIN_VERSION_API_MINOR 94
|
||||||
|
|
||||||
/* There is also a compatibity version number associated with the
|
/* There is also a compatibity version number associated with the
|
||||||
shared memory regions. It is incremented when incompatible
|
shared memory regions. It is incremented when incompatible
|
||||||
|
@ -38,11 +38,13 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int opterr; /* if error message should be printed */
|
#ifndef __INSIDE_CYGWIN__
|
||||||
extern int optind; /* index into parent argv vector */
|
extern int __declspec(dllimport) opterr; /* if error message should be printed */
|
||||||
extern int optopt; /* character checked for validity */
|
extern int __declspec(dllimport) optind; /* index into parent argv vector */
|
||||||
extern int optreset; /* reset getopt */
|
extern int __declspec(dllimport) optopt; /* character checked for validity */
|
||||||
extern char *optarg; /* argument associated with option */
|
extern int __declspec(dllimport) optreset; /* reset getopt */
|
||||||
|
extern char __declspec(dllimport) *optarg; /* argument associated with option */
|
||||||
|
#endif
|
||||||
|
|
||||||
int getopt (int, char * const *, const char *);
|
int getopt (int, char * const *, const char *);
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "winsup.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -52,11 +53,11 @@
|
|||||||
#ifdef __weak_alias
|
#ifdef __weak_alias
|
||||||
__weak_alias(getopt,_getopt)
|
__weak_alias(getopt,_getopt)
|
||||||
#endif
|
#endif
|
||||||
int opterr = 1; /* if error message should be printed */
|
int __declspec(dllexport) opterr; /* if error message should be printed */
|
||||||
int optind = 1; /* index into parent argv vector */
|
int __declspec(dllexport) optind; /* index into parent argv vector */
|
||||||
int optopt = '?'; /* character checked for validity */
|
int __declspec(dllexport) optopt; /* character checked for validity */
|
||||||
int optreset; /* reset getopt */
|
int __declspec(dllexport) optreset; /* reset getopt */
|
||||||
char *optarg; /* argument associated with option */
|
char __declspec(dllexport) *optarg; /* argument associated with option */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __weak_alias
|
#ifdef __weak_alias
|
||||||
@ -66,7 +67,7 @@ __weak_alias(getopt_long,_getopt_long)
|
|||||||
#ifndef __CYGWIN__
|
#ifndef __CYGWIN__
|
||||||
#define __progname __argv[0]
|
#define __progname __argv[0]
|
||||||
#else
|
#else
|
||||||
extern char __declspec(dllimport) *__progname;
|
extern char *__progname;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define IGNORE_FIRST (*options == '-' || *options == '+')
|
#define IGNORE_FIRST (*options == '-' || *options == '+')
|
@ -36,174 +36,52 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __CYGWIN__
|
#include "winsup.h"
|
||||||
#define HAVE_MALLOC_H
|
|
||||||
#define HAVE_STDLIB_H
|
|
||||||
#define HAVE_STRING_H
|
|
||||||
#define TIME_WITH_SYS_TIME
|
|
||||||
#define PATH_HEQUIV "/etc/hosts.equiv"
|
|
||||||
|
|
||||||
static int __ivaliduser();
|
|
||||||
static int __icheckhost();
|
|
||||||
|
|
||||||
struct hostent *cygwin_gethostbyname (const char *name);
|
|
||||||
unsigned long cygwin_inet_addr (const char *cp);
|
|
||||||
|
|
||||||
#define gethostbyname cygwin_gethostbyname
|
|
||||||
#define inet_addr cygwin_inet_addr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/file.h>
|
|
||||||
#include <sys/signal.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/uio.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#ifdef HAVE_MALLOC_H
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#include <string.h>
|
||||||
#if defined(STDC_HEADERS) || defined(HAVE_STDLIB_H)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_STRING_H
|
|
||||||
# include <string.h>
|
|
||||||
#endif
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#ifdef HAVE_ARPA_NAMESER_H
|
|
||||||
# include <arpa/nameser.h>
|
|
||||||
#endif
|
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#ifdef TIME_WITH_SYS_TIME
|
#include <sys/time.h>
|
||||||
# include <sys/time.h>
|
#include <time.h>
|
||||||
# include <time.h>
|
|
||||||
#else
|
#ifndef PATH_HEQUIV
|
||||||
# ifdef HAVE_SYS_TIME_H
|
# define PATH_HEQUIV "/etc/hosts.equiv"
|
||||||
# include <sys/time.h>
|
|
||||||
# else
|
|
||||||
# include <time.h>
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#ifndef __CYGWIN__
|
|
||||||
#include <resolv.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int __check_rhosts_file = 1;
|
int __check_rhosts_file = 1;
|
||||||
const char *__rcmd_errstr;
|
const char *__rcmd_errstr;
|
||||||
|
|
||||||
int
|
|
||||||
ruserok(rhost, superuser, ruser, luser)
|
|
||||||
const char *rhost;
|
|
||||||
int superuser;
|
|
||||||
const char *ruser;
|
|
||||||
const char *luser;
|
|
||||||
{
|
|
||||||
struct hostent *hp;
|
|
||||||
u_long addr;
|
|
||||||
char **ap;
|
|
||||||
|
|
||||||
if ((hp = gethostbyname(rhost)) == NULL)
|
|
||||||
return (-1);
|
|
||||||
for (ap = hp->h_addr_list; *ap; ++ap) {
|
|
||||||
bcopy(*ap, &addr, sizeof(addr));
|
|
||||||
if (iruserok(addr, superuser, ruser, luser) == 0)
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* New .rhosts strategy: We are passed an ip address. We spin through
|
* Returns "true" if match, 0 if no match.
|
||||||
* hosts.equiv and .rhosts looking for a match. When the .rhosts only
|
|
||||||
* has ip addresses, we don't have to trust a nameserver. When it
|
|
||||||
* contains hostnames, we spin through the list of addresses the nameserver
|
|
||||||
* gives us and look for a match.
|
|
||||||
*
|
|
||||||
* Returns 0 if ok, -1 if not ok.
|
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
iruserok(raddr, superuser, ruser, luser)
|
__icheckhost(raddr, lhost)
|
||||||
u_long raddr;
|
u_long raddr;
|
||||||
int superuser;
|
register char *lhost;
|
||||||
const char *ruser;
|
|
||||||
const char *luser;
|
|
||||||
{
|
{
|
||||||
register const char *cp;
|
register struct hostent *hp;
|
||||||
struct stat sbuf;
|
register u_long laddr;
|
||||||
struct passwd *pwd;
|
register char **pp;
|
||||||
FILE *hostf;
|
|
||||||
uid_t uid;
|
|
||||||
int first = 1;
|
|
||||||
char *pbuf;
|
|
||||||
|
|
||||||
first = 1;
|
/* Try for raw ip address first. */
|
||||||
hostf = superuser ? NULL : fopen(PATH_HEQUIV, "r");
|
if (isdigit(*lhost) && (long)(laddr = cygwin_inet_addr(lhost)) != -1)
|
||||||
again:
|
return (raddr == laddr);
|
||||||
if (hostf) {
|
|
||||||
if (__ivaliduser(hostf, raddr, luser, ruser) == 0) {
|
|
||||||
(void) fclose(hostf);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
(void) fclose(hostf);
|
|
||||||
}
|
|
||||||
if (first == 1 && (__check_rhosts_file || superuser)) {
|
|
||||||
first = 0;
|
|
||||||
if ((pwd = getpwnam(luser)) == NULL)
|
|
||||||
return(-1);
|
|
||||||
|
|
||||||
pbuf = malloc (strlen (pwd->pw_dir) + sizeof "/.rhosts");
|
/* Better be a hostname. */
|
||||||
if (! pbuf)
|
if ((hp = cygwin_gethostbyname(lhost)) == NULL)
|
||||||
{
|
return (0);
|
||||||
errno = ENOMEM;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
strcpy (pbuf, pwd->pw_dir);
|
|
||||||
strcat (pbuf, "/.rhosts");
|
|
||||||
|
|
||||||
/*
|
/* Spin through ip addresses. */
|
||||||
* Change effective uid while opening .rhosts. If root and
|
for (pp = hp->h_addr_list; *pp; ++pp)
|
||||||
* reading an NFS mounted file system, can't read files that
|
if (!bcmp(&raddr, *pp, sizeof(u_long)))
|
||||||
* are protected read/write owner only.
|
return (1);
|
||||||
*/
|
|
||||||
uid = geteuid();
|
|
||||||
(void)seteuid(pwd->pw_uid);
|
|
||||||
hostf = fopen(pbuf, "r");
|
|
||||||
(void)seteuid(uid);
|
|
||||||
|
|
||||||
if (hostf == NULL)
|
/* No match. */
|
||||||
return(-1);
|
return (0);
|
||||||
/*
|
|
||||||
* If not a regular file, or is owned by someone other than
|
|
||||||
* user or root or if writeable by anyone but the owner, quit.
|
|
||||||
*/
|
|
||||||
cp = NULL;
|
|
||||||
if (lstat(pbuf, &sbuf) < 0)
|
|
||||||
cp = ".rhosts not regular file";
|
|
||||||
else if (!S_ISREG(sbuf.st_mode))
|
|
||||||
cp = ".rhosts not regular file";
|
|
||||||
else if (fstat(fileno(hostf), &sbuf) < 0)
|
|
||||||
cp = ".rhosts fstat failed";
|
|
||||||
else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid)
|
|
||||||
cp = "bad .rhosts owner";
|
|
||||||
else if (sbuf.st_mode & (S_IWGRP|S_IWOTH))
|
|
||||||
cp = ".rhosts writeable by other than owner";
|
|
||||||
/* If there were any problems, quit. */
|
|
||||||
if (cp) {
|
|
||||||
__rcmd_errstr = (char *) cp;
|
|
||||||
fclose(hostf);
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
goto again;
|
|
||||||
}
|
|
||||||
return (-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -212,12 +90,9 @@ again:
|
|||||||
*
|
*
|
||||||
* Returns 0 if ok, -1 if not ok.
|
* Returns 0 if ok, -1 if not ok.
|
||||||
*/
|
*/
|
||||||
#ifdef __CYGWIN__
|
static int
|
||||||
static
|
|
||||||
#endif
|
|
||||||
int
|
|
||||||
__ivaliduser(hostf, raddr, luser, ruser)
|
__ivaliduser(hostf, raddr, luser, ruser)
|
||||||
FILE *hostf;
|
struct __sFILE64 *hostf;
|
||||||
u_long raddr;
|
u_long raddr;
|
||||||
const char *luser;
|
const char *luser;
|
||||||
const char *ruser;
|
const char *ruser;
|
||||||
@ -287,33 +162,109 @@ __ivaliduser(hostf, raddr, luser, ruser)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns "true" if match, 0 if no match.
|
* New .rhosts strategy: We are passed an ip address. We spin through
|
||||||
|
* hosts.equiv and .rhosts looking for a match. When the .rhosts only
|
||||||
|
* has ip addresses, we don't have to trust a nameserver. When it
|
||||||
|
* contains hostnames, we spin through the list of addresses the nameserver
|
||||||
|
* gives us and look for a match.
|
||||||
|
*
|
||||||
|
* Returns 0 if ok, -1 if not ok.
|
||||||
*/
|
*/
|
||||||
#ifdef __CYGWIN__
|
|
||||||
static
|
|
||||||
#endif
|
|
||||||
int
|
int
|
||||||
__icheckhost(raddr, lhost)
|
iruserok(raddr, superuser, ruser, luser)
|
||||||
u_long raddr;
|
u_long raddr;
|
||||||
register char *lhost;
|
int superuser;
|
||||||
|
const char *ruser;
|
||||||
|
const char *luser;
|
||||||
{
|
{
|
||||||
register struct hostent *hp;
|
register const char *cp;
|
||||||
register u_long laddr;
|
struct __stat64 sbuf;
|
||||||
register char **pp;
|
struct passwd *pwd;
|
||||||
|
struct __sFILE64 *hostf;
|
||||||
|
|
||||||
/* Try for raw ip address first. */
|
uid_t uid;
|
||||||
if (isdigit(*lhost) && (long)(laddr = inet_addr(lhost)) != -1)
|
int first = 1;
|
||||||
return (raddr == laddr);
|
char *pbuf;
|
||||||
|
|
||||||
/* Better be a hostname. */
|
first = 1;
|
||||||
if ((hp = gethostbyname(lhost)) == NULL)
|
hostf = superuser ? NULL : fopen64(PATH_HEQUIV, "rt");
|
||||||
return (0);
|
again:
|
||||||
|
if (hostf) {
|
||||||
|
if (__ivaliduser(hostf, raddr, luser, ruser) == 0) {
|
||||||
|
(void) fclose(hostf);
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
(void) fclose(hostf);
|
||||||
|
}
|
||||||
|
if (first == 1 && (__check_rhosts_file || superuser)) {
|
||||||
|
first = 0;
|
||||||
|
if ((pwd = getpwnam(luser)) == NULL)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
/* Spin through ip addresses. */
|
pbuf = malloc (strlen (pwd->pw_dir) + sizeof "/.rhosts");
|
||||||
for (pp = hp->h_addr_list; *pp; ++pp)
|
if (! pbuf)
|
||||||
if (!bcmp(&raddr, *pp, sizeof(u_long)))
|
{
|
||||||
return (1);
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
strcpy (pbuf, pwd->pw_dir);
|
||||||
|
strcat (pbuf, "/.rhosts");
|
||||||
|
|
||||||
/* No match. */
|
/*
|
||||||
return (0);
|
* Change effective uid while opening .rhosts. If root and
|
||||||
|
* reading an NFS mounted file system, can't read files that
|
||||||
|
* are protected read/write owner only.
|
||||||
|
*/
|
||||||
|
uid = geteuid32();
|
||||||
|
(void)seteuid32(pwd->pw_uid);
|
||||||
|
hostf = fopen64(pbuf, "rt");
|
||||||
|
(void)seteuid32(uid);
|
||||||
|
|
||||||
|
if (hostf == NULL)
|
||||||
|
return(-1);
|
||||||
|
/*
|
||||||
|
* If not a regular file, or is owned by someone other than
|
||||||
|
* user or root or if writeable by anyone but the owner, quit.
|
||||||
|
*/
|
||||||
|
cp = NULL;
|
||||||
|
if (lstat64(pbuf, &sbuf) < 0)
|
||||||
|
cp = ".rhosts not regular file";
|
||||||
|
else if (!S_ISREG(sbuf.st_mode))
|
||||||
|
cp = ".rhosts not regular file";
|
||||||
|
else if (fstat64(fileno(hostf), &sbuf) < 0)
|
||||||
|
cp = ".rhosts fstat failed";
|
||||||
|
else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid)
|
||||||
|
cp = "bad .rhosts owner";
|
||||||
|
else if (sbuf.st_mode & (S_IWGRP|S_IWOTH))
|
||||||
|
cp = ".rhosts writeable by other than owner";
|
||||||
|
/* If there were any problems, quit. */
|
||||||
|
if (cp) {
|
||||||
|
__rcmd_errstr = (char *) cp;
|
||||||
|
fclose(hostf);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ruserok(rhost, superuser, ruser, luser)
|
||||||
|
const char *rhost;
|
||||||
|
int superuser;
|
||||||
|
const char *ruser;
|
||||||
|
const char *luser;
|
||||||
|
{
|
||||||
|
struct hostent *hp;
|
||||||
|
u_long addr;
|
||||||
|
char **ap;
|
||||||
|
|
||||||
|
if ((hp = cygwin_gethostbyname(rhost)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
for (ap = hp->h_addr_list; *ap; ++ap) {
|
||||||
|
bcopy(*ap, &addr, sizeof(addr));
|
||||||
|
if (iruserok(addr, superuser, ruser, luser) == 0)
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
}
|
}
|
@ -2919,7 +2919,7 @@ long gethostid(void)
|
|||||||
|
|
||||||
#define ETC_SHELLS "/etc/shells"
|
#define ETC_SHELLS "/etc/shells"
|
||||||
static int shell_index;
|
static int shell_index;
|
||||||
static FILE *shell_fp;
|
static struct __sFILE64 *shell_fp;
|
||||||
|
|
||||||
extern "C" char *
|
extern "C" char *
|
||||||
getusershell ()
|
getusershell ()
|
||||||
@ -2938,7 +2938,7 @@ getusershell ()
|
|||||||
static char buf[MAX_PATH];
|
static char buf[MAX_PATH];
|
||||||
int ch, buf_idx;
|
int ch, buf_idx;
|
||||||
|
|
||||||
if (!shell_fp && !(shell_fp = fopen (ETC_SHELLS, "rt")))
|
if (!shell_fp && !(shell_fp = fopen64 (ETC_SHELLS, "rt")))
|
||||||
{
|
{
|
||||||
if (def_shells[shell_index])
|
if (def_shells[shell_index])
|
||||||
return strcpy (buf, def_shells[shell_index++]);
|
return strcpy (buf, def_shells[shell_index++]);
|
||||||
|
@ -37,14 +37,20 @@ details. */
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/strace.h>
|
#include <sys/strace.h>
|
||||||
|
|
||||||
|
/* Declarations for functions used in C and C++ code. */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
extern __uid32_t getuid32 (void);
|
extern __uid32_t getuid32 (void);
|
||||||
extern __uid32_t geteuid32 (void);
|
extern __uid32_t geteuid32 (void);
|
||||||
|
extern int seteuid32 (__uid32_t);
|
||||||
extern __gid32_t getegid32 (void);
|
extern __gid32_t getegid32 (void);
|
||||||
extern struct passwd *getpwuid32 (__uid32_t);
|
extern struct passwd *getpwuid32 (__uid32_t);
|
||||||
struct passwd *getpwnam (const char *);
|
extern struct passwd *getpwnam (const char *);
|
||||||
|
extern struct __sFILE64 *fopen64 (const char *, const char *);
|
||||||
|
extern struct hostent *cygwin_gethostbyname (const char *name);
|
||||||
|
extern unsigned long cygwin_inet_addr (const char *cp);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user