- (djm) Big KNF on openbsd-compat/

This commit is contained in:
Damien Miller 2003-05-19 00:13:38 +10:00
parent e323df6c48
commit 317412502b
23 changed files with 867 additions and 941 deletions

View File

@ -17,6 +17,7 @@
- (djm) Remove IPv4 by default hack now that we can specify AF in config - (djm) Remove IPv4 by default hack now that we can specify AF in config
- (djm) Tidy and trim TODO - (djm) Tidy and trim TODO
- (djm) Sync openbsd-compat/ with OpenBSD CVS head - (djm) Sync openbsd-compat/ with OpenBSD CVS head
- (djm) Big KNF on openbsd-compat/
20030517 20030517
- (bal) strcat -> strlcat on openbsd-compat/realpath.c (rev 1.8 OpenBSD) - (bal) strcat -> strlcat on openbsd-compat/realpath.c (rev 1.8 OpenBSD)
@ -1572,4 +1573,4 @@
save auth method before monitor_reset_key_state(); bugzilla bug #284; save auth method before monitor_reset_key_state(); bugzilla bug #284;
ok provos@ ok provos@
$Id: ChangeLog,v 1.2738 2003/05/18 12:24:09 djm Exp $ $Id: ChangeLog,v 1.2739 2003/05/18 14:13:38 djm Exp $

View File

@ -25,7 +25,7 @@
#include "includes.h" #include "includes.h"
#include "log.h" #include "log.h"
RCSID("$Id: bsd-arc4random.c,v 1.6 2003/03/17 05:13:53 djm Exp $"); RCSID("$Id: bsd-arc4random.c,v 1.7 2003/05/18 14:13:38 djm Exp $");
#ifndef HAVE_ARC4RANDOM #ifndef HAVE_ARC4RANDOM
@ -70,6 +70,7 @@ void arc4random_stir(void)
fatal("Couldn't obtain random bytes (error %ld)", fatal("Couldn't obtain random bytes (error %ld)",
ERR_get_error()); ERR_get_error());
RC4_set_key(&rc4, sizeof(rand_buf), rand_buf); RC4_set_key(&rc4, sizeof(rand_buf), rand_buf);
RC4(&rc4, sizeof(rand_buf), rand_buf, rand_buf);
memset(rand_buf, 0, sizeof(rand_buf)); memset(rand_buf, 0, sizeof(rand_buf));
rc4_ready = REKEY_BYTES; rc4_ready = REKEY_BYTES;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: bsd-cray.c,v 1.10 2003/05/02 21:32:56 dtucker Exp $ * $Id: bsd-cray.c,v 1.11 2003/05/18 14:13:38 djm Exp $
* *
* bsd-cray.c * bsd-cray.c
* *
@ -92,14 +92,15 @@ cray_login_failure(char *username, int errcode)
struct jtab jtab; /* job table structure */ struct jtab jtab; /* job table structure */
int jid = 0; /* job id */ int jid = 0; /* job id */
if ((jid = getjtab(&jtab)) < 0) { if ((jid = getjtab(&jtab)) < 0)
debug("cray_login_failure(): getjtab error"); debug("cray_login_failure(): getjtab error");
}
getsysudb(); getsysudb();
if ((ueptr = getudbnam(username)) == UDB_NULL) { if ((ueptr = getudbnam(username)) == UDB_NULL)
debug("cray_login_failure(): getudbname() returned NULL"); debug("cray_login_failure(): getudbname() returned NULL");
}
endudb(); endudb();
memset(&fsent, '\0', sizeof(fsent));
fsent.revision = 0; fsent.revision = 0;
fsent.uname = username; fsent.uname = username;
fsent.host = (char *)get_canonical_hostname(options.verify_reverse_mapping); fsent.host = (char *)get_canonical_hostname(options.verify_reverse_mapping);
@ -132,14 +133,15 @@ cray_access_denied(char *username)
errcode = 0; errcode = 0;
getsysudb(); getsysudb();
if ((ueptr = getudbnam(username)) == UDB_NULL) { if ((ueptr = getudbnam(username)) == UDB_NULL)
debug("cray_login_failure(): getudbname() returned NULL"); debug("cray_login_failure(): getudbname() returned NULL");
}
endudb(); endudb();
if (ueptr && ueptr->ue_disabled)
if (ueptr != NULL && ueptr->ue_disabled)
errcode = IA_DISABLED; errcode = IA_DISABLED;
if (errcode) if (errcode)
cray_login_failure(username, errcode); cray_login_failure(username, errcode);
return (errcode); return (errcode);
} }
@ -177,13 +179,10 @@ cray_setup (uid_t uid, char *username, const char *command)
char *sr; /* status return from setlimits() */ char *sr; /* status return from setlimits() */
char *ttyn = NULL; /* ttyname or command name*/ char *ttyn = NULL; /* ttyname or command name*/
char hostname[MAXHOSTNAMELEN]; char hostname[MAXHOSTNAMELEN];
passwd_t pwdacm, /* passwd stuff for ia_user */
pwddialup, passwd_t pwdacm, pwddialup, pwdudb, pwdwal, pwddce;
pwdudb,
pwdwal,
pwddce; /* passwd stuff for ia_user */
ia_user_ret_t uret; /* stuff returned from ia_user */ ia_user_ret_t uret; /* stuff returned from ia_user */
ia_user_t usent; /* ia_user main structure */ ia_user_t usent /* ia_user main structure */
int ia_rcode; /* ia_user return code */ int ia_rcode; /* ia_user return code */
ia_failure_t fsent; /* ia_failure structure */ ia_failure_t fsent; /* ia_failure structure */
ia_failure_ret_t fret; /* ia_failure return stuff */ ia_failure_ret_t fret; /* ia_failure return stuff */
@ -195,53 +194,45 @@ cray_setup (uid_t uid, char *username, const char *command)
if (SecureSys = (int)sysconf(_SC_CRAY_SECURE_SYS)) { if (SecureSys = (int)sysconf(_SC_CRAY_SECURE_SYS)) {
getsysv(&sysv, sizeof(struct sysv)); getsysv(&sysv, sizeof(struct sysv));
minslevel = sysv.sy_minlvl; minslevel = sysv.sy_minlvl;
if (getusrv(&usrv) < 0) { if (getusrv(&usrv) < 0)
debug("getusrv() failed, errno = %d",errno); fatal("getusrv() failed, errno = %d", errno);
exit(1);
}
} }
hostname[0] = '\0'; hostname[0] = '\0';
strncpy(hostname, strlcpy(hostname,
(char *)get_canonical_hostname(options.verify_reverse_mapping), (char *)get_canonical_hostname(options.verify_reverse_mapping),
MAXHOSTNAMELEN); MAXHOSTNAMELEN);
/* /*
* Fetch user's UDB entry. * Fetch user's UDB entry.
*/ */
getsysudb(); getsysudb();
if ((up = getudbnam(username)) == UDB_NULL) { if ((up = getudbnam(username)) == UDB_NULL)
debug("cannot fetch user's UDB entry"); fatal("cannot fetch user's UDB entry");
exit(1);
}
/* /*
* Prevent any possible fudging so perform a data * Prevent any possible fudging so perform a data
* safety check and compare the supplied uid against * safety check and compare the supplied uid against
* the udb's uid. * the udb's uid.
*/ */
if (up->ue_uid != uid) { if (up->ue_uid != uid)
debug("IA uid missmatch"); fatal("IA uid missmatch");
exit(1);
}
endudb(); endudb();
if ((jid = getjtab(&jtab)) < 0) { if ((jid = getjtab(&jtab)) < 0) {
debug("getjtab"); debug("getjtab");
return -1; return(-1);
} }
pid = getpid(); pid = getpid();
ttyn = ttyname(0); ttyn = ttyname(0);
if (SecureSys) { if (SecureSys) {
if (ttyn) { if (ttyn != NULL)
secstatrc = secstat(ttyn, &secinfo); secstatrc = secstat(ttyn, &secinfo);
} else { else
secstatrc = fsecstat(1, &secinfo); secstatrc = fsecstat(1, &secinfo);
}
if (secstatrc == 0) { if (secstatrc == 0)
debug("[f]secstat() successful"); debug("[f]secstat() successful");
} else { else
debug("[f]secstat() error, rc = %d", secstatrc); fatal("[f]secstat() error, rc = %d", secstatrc);
exit(1);
}
} }
if ((ttyn == NULL) && ((char *)command != NULL)) if ((ttyn == NULL) && ((char *)command != NULL))
ttyn = (char *)command; ttyn = (char *)command;
@ -282,7 +273,6 @@ cray_setup (uid_t uid, char *username, const char *command)
uret.normal = 0; uret.normal = 0;
ia_rcode = ia_user(&usent, &uret); ia_rcode = ia_user(&usent, &uret);
switch (ia_rcode) { switch (ia_rcode) {
/* /*
* These are acceptable return codes from ia_user() * These are acceptable return codes from ia_user()
@ -299,27 +289,29 @@ cray_setup (uid_t uid, char *username, const char *command)
execl("/bin/passwd", "passwd", username, 0); execl("/bin/passwd", "passwd", username, 0);
exit(9); exit(9);
} }
break; break;
case IA_NORMAL: /* Normal Return Code */ case IA_NORMAL: /* Normal Return Code */
break; break;
case IA_BACKDOOR: case IA_BACKDOOR:
strcpy(ue.ue_name, "root"); /* XXX: can we memset it to zero here so save some of this */
strcpy(ue.ue_passwd, ""); strlcpy(ue.ue_name, "root", sizeof(ue.ue_name));
strcpy(ue.ue_dir, "/"); strlcpy(ue.ue_dir, "/", sizeof(ue.ue_dir));
strcpy(ue.ue_shell, "/bin/sh"); strlcpy(ue.ue_shell, "/bin/sh", sizeof(ue.ue_shell));
strcpy(ue.ue_age, "");
strcpy(ue.ue_comment, ""); ue.ue_passwd[0] = '\0';
strcpy(ue.ue_loghost, ""); ue.ue_age[0] = '\0';
strcpy(ue.ue_logline, ""); ue.ue_comment[0] = '\0';
ue.ue_loghost[0] = '\0';
ue.ue_logline[0] = '\0';
ue.ue_uid = -1; ue.ue_uid = -1;
ue.ue_nice[UDBRC_INTER] = 0; ue.ue_nice[UDBRC_INTER] = 0;
for (i = 0; i < MAXVIDS; i++) for (i = 0; i < MAXVIDS; i++)
ue.ue_gids[i] = 0; ue.ue_gids[i] = 0;
ue.ue_logfails = 0; ue.ue_logfails = 0;
ue.ue_minlvl=minslevel; ue.ue_minlvl = ue.ue_maxlvl = ue.ue_deflvl = minslevel;
ue.ue_maxlvl=minslevel;
ue.ue_deflvl=minslevel;
ue.ue_defcomps = 0; ue.ue_defcomps = 0;
ue.ue_comparts = 0; ue.ue_comparts = 0;
ue.ue_permits = 0; ue.ue_permits = 0;
@ -340,8 +332,6 @@ cray_setup (uid_t uid, char *username, const char *command)
case IA_BADAUTH: case IA_BADAUTH:
printf("Bad authorization, access denied.\n"); printf("Bad authorization, access denied.\n");
break; break;
case IA_DIALUPERR:
break;
case IA_DISABLED: case IA_DISABLED:
printf("Your login has been disabled. Contact the system "); printf("Your login has been disabled. Contact the system ");
printf("administrator for assistance.\n"); printf("administrator for assistance.\n");
@ -349,42 +339,18 @@ cray_setup (uid_t uid, char *username, const char *command)
case IA_GETSYSV: case IA_GETSYSV:
printf("getsysv() failed - errno = %d\n", errno); printf("getsysv() failed - errno = %d\n", errno);
break; break;
case IA_LOCALHOST:
break;
case IA_MAXLOGS: case IA_MAXLOGS:
printf("Maximum number of failed login attempts exceeded.\n"); printf("Maximum number of failed login attempts exceeded.\n");
printf("Access denied.\n"); printf("Access denied.\n");
break; break;
case IA_NOPASS:
break;
case IA_PUBLIC:
break;
case IA_SECURIDERR:
break;
case IA_CONSOLE:
break;
case IA_TRUSTED:
break;
case IA_UDBERR:
break;
case IA_UDBPWDNULL: case IA_UDBPWDNULL:
/* if (SecureSys)
* NULL password not allowed on MLS systems
*/
if (SecureSys) {
printf("NULL Password not allowed on MLS systems.\n"); printf("NULL Password not allowed on MLS systems.\n");
}
break;
case IA_UNKNOWN:
break;
case IA_UNKNOWNYP:
break;
case IA_WALERR:
break; break;
default: default:
/* nothing special */ break;
; }
} /* 2. switch (ia_rcode) */
/* /*
* Authentication failed. * Authentication failed.
*/ */
@ -414,11 +380,11 @@ cray_setup (uid_t uid, char *username, const char *command)
* Call ia_failure because of an IA failure. * Call ia_failure because of an IA failure.
* There is no return because ia_failure exits. * There is no return because ia_failure exits.
*/ */
ia_failure(&fsent, &fret); ia_failure(&fsent, &fret);
exit(1); exit(1);
} /* 1. switch (ia_rcode) */ }
ia_mlsrcode = IA_NORMAL; ia_mlsrcode = IA_NORMAL;
if (SecureSys) { if (SecureSys) {
debug("calling ia_mlsuser()"); debug("calling ia_mlsuser()");
@ -455,18 +421,22 @@ cray_setup (uid_t uid, char *username, const char *command)
/* Provide login status information */ /* Provide login status information */
if (options.print_lastlog && ue.ue_logtime != 0) { if (options.print_lastlog && ue.ue_logtime != 0) {
printf("Last successful login was : %.*s ", printf("Last successful login was : %.*s ", 19,
19, (char *)ctime(&ue.ue_logtime)); (char *)ctime(&ue.ue_logtime));
if (*ue.ue_loghost != '\0') if (*ue.ue_loghost != '\0') {
printf("from %.*s\n", sizeof(ue.ue_loghost), ue.ue_loghost); printf("from %.*s\n", sizeof(ue.ue_loghost),
ue.ue_loghost);
else printf("on %.*s\n", sizeof(ue.ue_logline), ue.ue_logline); } else {
printf("on %.*s\n", sizeof(ue.ue_logline),
if ( SecureSys && (ue.ue_logfails != 0)) ue.ue_logline);
printf(" followed by %d failed attempts\n", ue.ue_logfails);
} }
if (SecureSys && (ue.ue_logfails != 0)) {
printf(" followed by %d failed attempts\n",
ue.ue_logfails);
}
}
/* /*
* Call ia_success to process successful I/A. * Call ia_success to process successful I/A.
@ -499,14 +469,14 @@ cray_setup (uid_t uid, char *username, const char *command)
while (valid_acct == -1) { while (valid_acct == -1) {
printf("Account (? for available accounts)" printf("Account (? for available accounts)"
" [%s]: ", acid2nam(ue.ue_acids[0])); " [%s]: ", acid2nam(ue.ue_acids[0]));
gets(acct_name); fgets(acct_name, MAXACID, stdin);
switch (acct_name[0]) { switch (acct_name[0]) {
case EOF: case EOF:
exit(0); exit(0);
break; break;
case '\0': case '\0':
valid_acct = ue.ue_acids[0]; valid_acct = ue.ue_acids[0];
strcpy(acct_name, acid2nam(valid_acct)); strlcpy(acct_name, acid2nam(valid_acct), MAXACID);
break; break;
case '?': case '?':
/* Print the list 3 wide */ /* Print the list 3 wide */
@ -522,14 +492,18 @@ cray_setup (uid_t uid, char *username, const char *command)
printf(" %s", printf(" %s",
acid2nam(ue.ue_acids[i])); acid2nam(ue.ue_acids[i]));
} }
if (ue.ue_permbits & PERMBITS_ACCTID) if (ue.ue_permbits & PERMBITS_ACCTID) {
printf("\"acctid\" permbit also allows" printf("\"acctid\" permbit also allows"
" you to select any valid " " you to select any valid "
"account name.\n"); "account name.\n");
}
printf("\n"); printf("\n");
break; break;
default: default:
if ((valid_acct = nam2acid(acct_name)) == -1) printf("Account id not found for" valid_acct = nam2acid(acct_name);
if (valid_acct == -1) {
printf(
"Account id not found for"
" account name \"%s\"\n\n", " account name \"%s\"\n\n",
acct_name); acct_name);
break; break;
@ -561,7 +535,8 @@ cray_setup (uid_t uid, char *username, const char *command)
* The client isn't connected to a terminal and can't * The client isn't connected to a terminal and can't
* respond to an acid prompt. Use default acid. * respond to an acid prompt. Use default acid.
*/ */
debug("cray_setup: ttyname false case, %.100s", ttyname); debug("cray_setup: ttyname false case, %.100s",
ttyname);
valid_acct = ue.ue_acids[0]; valid_acct = ue.ue_acids[0];
} }
} else { } else {
@ -576,12 +551,14 @@ cray_setup (uid_t uid, char *username, const char *command)
exit(1); exit(1);
} }
/* set up shares and quotas */ /*
/* Now set shares, quotas, limits, including CPU time for the (interactive) * Now set shares, quotas, limits, including CPU time for the
* job and process, and set up permissions (for chown etc), etc. * (interactive) job and process, and set up permissions
* (for chown etc), etc.
*/ */
if (setshares(ue.ue_uid, valid_acct, printf, 0, 0)) { if (setshares(ue.ue_uid, valid_acct, printf, 0, 0)) {
printf("Unable to give %d shares to <%s>(%d/%d)\n", ue.ue_shares, ue.ue_name, ue.ue_uid, valid_acct); printf("Unable to give %d shares to <%s>(%d/%d)\n",
ue.ue_shares, ue.ue_name, ue.ue_uid, valid_acct);
exit(1); exit(1);
} }
@ -601,12 +578,10 @@ cray_setup (uid_t uid, char *username, const char *command)
* There exist double defines for the job/session table in * There exist double defines for the job/session table in
* unicos/mk (jtab.h) so no need for a compile time switch. * unicos/mk (jtab.h) so no need for a compile time switch.
*/ */
bzero((char *)&init_info, sizeof(struct servprov)); memset(&init_info, '\0', sizeof(init_info));
init_info.s_sessinit.si_id = URM_SPT_LOGIN; init_info.s_sessinit.si_id = URM_SPT_LOGIN;
init_info.s_sessinit.si_pid = getpid(); init_info.s_sessinit.si_pid = getpid();
init_info.s_sessinit.si_sid = jid; init_info.s_sessinit.si_sid = jid;
init_info.s_routing.seqno = 0;
init_info.s_routing.iadrs = 0;
sesscntl(0, S_SETSERVPO, (int)&init_info); sesscntl(0, S_SETSERVPO, (int)&init_info);
/* /*
@ -663,15 +638,17 @@ drop_cray_privs()
usrv.sv_intcat = TFM_SYSTEM; usrv.sv_intcat = TFM_SYSTEM;
usrv.sv_valcat |= (TFM_SYSTEM | TFM_SYSFILE); usrv.sv_valcat |= (TFM_SYSTEM | TFM_SYSFILE);
if (setusrv(&usrv) < 0) if (setusrv(&usrv) < 0) {
fatal("%s(%d): setusrv(): %s", __FILE__, __LINE__, fatal("%s(%d): setusrv(): %s", __FILE__, __LINE__,
strerror(errno)); strerror(errno));
}
if ((privstate = priv_init_proc()) != NULL) { if ((privstate = priv_init_proc()) != NULL) {
result = priv_set_proc(privstate); result = priv_set_proc(privstate);
if (result != 0 ) if (result != 0 ) {
fatal("%s(%d): priv_set_proc(): %s", fatal("%s(%d): priv_set_proc(): %s",
__FILE__, __LINE__, strerror(errno)); __FILE__, __LINE__, strerror(errno));
}
priv_free_proc(privstate); priv_free_proc(privstate);
} }
debug ("Privileges should be cleared..."); debug ("Privileges should be cleared...");
@ -692,6 +669,7 @@ cray_retain_utmp(struct utmp *ut, int pid)
struct utmp utmp; struct utmp utmp;
if ((fd = open(UTMP_FILE, O_RDONLY)) != -1) { if ((fd = open(UTMP_FILE, O_RDONLY)) != -1) {
/* XXX use atomicio */
while (read(fd, (char *)&utmp, sizeof(utmp)) == sizeof(utmp)) { while (read(fd, (char *)&utmp, sizeof(utmp)) == sizeof(utmp)) {
if (pid == utmp.ut_pid) { if (pid == utmp.ut_pid) {
ut->ut_jid = utmp.ut_jid; ut->ut_jid = utmp.ut_jid;
@ -702,8 +680,7 @@ cray_retain_utmp(struct utmp *ut, int pid)
} }
} }
close(fd); close(fd);
} } else
else
fatal("Unable to open utmp file"); fatal("Unable to open utmp file");
} }
@ -717,11 +694,9 @@ cray_retain_utmp(struct utmp *ut, int pid)
void void
cray_delete_tmpdir(char *login, int jid, uid_t uid) cray_delete_tmpdir(char *login, int jid, uid_t uid)
{ {
int child;
static char jtmp[TPATHSIZ]; static char jtmp[TPATHSIZ];
struct stat statbuf; struct stat statbuf;
int c; int child, c, wstat;
int wstat;
for (c = 'a'; c <= 'z'; c++) { for (c = 'a'; c <= 'z'; c++) {
snprintf(jtmp, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c); snprintf(jtmp, TPATHSIZ, "%s/jtmp.%06d%c", JTMPDIR, jid, c);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: bsd-cray.h,v 1.8 2003/05/02 13:42:25 dtucker Exp $ * $Id: bsd-cray.h,v 1.9 2003/05/18 14:13:39 djm Exp $
* *
* bsd-cray.h * bsd-cray.h
* *
@ -38,13 +38,15 @@
#define _BSD_CRAY_H #define _BSD_CRAY_H
#ifdef _UNICOS #ifdef _UNICOS
void cray_init_job(struct passwd *); /* init cray job */
void cray_job_termination_handler(int); /* process end of job signal */ void cray_init_job(struct passwd *);
void cray_login_failure(char *username, int errcode); void cray_job_termination_handler(int);
int cray_access_denied(char *username); void cray_login_failure(char *, int );
int cray_access_denied(char *);
#define CUSTOM_FAILED_LOGIN 1 #define CUSTOM_FAILED_LOGIN 1
void record_failed_login(const char *user, const char *ttyname); void record_failed_login(const char *, const char *);
extern char cray_tmpdir[]; /* cray tmpdir */ extern char cray_tmpdir[];
#ifndef IA_SSHD #ifndef IA_SSHD
# define IA_SSHD IA_LOGIN # define IA_SSHD IA_LOGIN
#endif #endif
@ -55,6 +57,7 @@ extern char cray_tmpdir[]; /* cray tmpdir */
# include <sys/ttold.h> # include <sys/ttold.h>
# define TIOCGPGRP (tIOC|20) # define TIOCGPGRP (tIOC|20)
#endif #endif
#endif
#endif /* UNICOS */
#endif /* _BSD_CRAY_H */ #endif /* _BSD_CRAY_H */

View File

@ -31,7 +31,7 @@
#include "includes.h" #include "includes.h"
RCSID("$Id: bsd-cygwin_util.c,v 1.9 2002/11/09 15:59:29 mouring Exp $"); RCSID("$Id: bsd-cygwin_util.c,v 1.10 2003/05/18 14:13:39 djm Exp $");
#ifdef HAVE_CYGWIN #ifdef HAVE_CYGWIN
@ -53,7 +53,8 @@ RCSID("$Id: bsd-cygwin_util.c,v 1.9 2002/11/09 15:59:29 mouring Exp $");
# undef pipe # undef pipe
#endif #endif
int binary_open(const char *filename, int flags, ...) int
binary_open(const char *filename, int flags, ...)
{ {
va_list ap; va_list ap;
mode_t mode; mode_t mode;
@ -61,10 +62,11 @@ int binary_open(const char *filename, int flags, ...)
va_start(ap, flags); va_start(ap, flags);
mode = va_arg(ap, mode_t); mode = va_arg(ap, mode_t);
va_end(ap); va_end(ap);
return open(filename, flags | O_BINARY, mode); return (open(filename, flags | O_BINARY, mode));
} }
int binary_pipe(int fd[2]) int
binary_pipe(int fd[2])
{ {
int ret = pipe(fd); int ret = pipe(fd);
@ -72,41 +74,41 @@ int binary_pipe(int fd[2])
setmode(fd[0], O_BINARY); setmode(fd[0], O_BINARY);
setmode(fd[1], O_BINARY); setmode(fd[1], O_BINARY);
} }
return ret; return (ret);
} }
#define HAS_CREATE_TOKEN 1 #define HAS_CREATE_TOKEN 1
#define HAS_NTSEC_BY_DEFAULT 2 #define HAS_NTSEC_BY_DEFAULT 2
static int has_capability(int what) static int
has_capability(int what)
{ {
/* has_capability() basically calls uname() and checks if
specific capabilities of Cygwin can be evaluated from that.
This simplifies the calling functions which only have to ask
for a capability using has_capability() instead of having
to figure that out by themselves. */
static int inited; static int inited;
static int has_create_token; static int has_create_token;
static int has_ntsec_by_default; static int has_ntsec_by_default;
/*
* has_capability() basically calls uname() and checks if
* specific capabilities of Cygwin can be evaluated from that.
* This simplifies the calling functions which only have to ask
* for a capability using has_capability() instead of having
* to figure that out by themselves.
*/
if (!inited) { if (!inited) {
struct utsname uts; struct utsname uts;
char *c; char *c;
if (!uname(&uts)) { if (!uname(&uts)) {
int major_high = 0; int major_high = 0, major_low = 0, minor = 0;
int major_low = 0; int api_major_version = 0, api_minor_version = 0;
int minor = 0;
int api_major_version = 0;
int api_minor_version = 0;
char *c; char *c;
sscanf(uts.release, "%d.%d.%d", &major_high, sscanf(uts.release, "%d.%d.%d", &major_high,
&major_low, &minor); &major_low, &minor);
c = strchr(uts.release, '('); if ((c = strchr(uts.release, '(')) != NULL) {
if (c)
sscanf(c + 1, "%d.%d", &api_major_version, sscanf(c + 1, "%d.%d", &api_major_version,
&api_minor_version); &api_minor_version);
}
if (major_high > 1 || if (major_high > 1 ||
(major_high == 1 && (major_low > 3 || (major_high == 1 && (major_low > 3 ||
(major_low == 3 && minor >= 2)))) (major_low == 3 && minor >= 2))))
@ -118,14 +120,15 @@ static int has_capability(int what)
} }
switch (what) { switch (what) {
case HAS_CREATE_TOKEN: case HAS_CREATE_TOKEN:
return has_create_token; return (has_create_token);
case HAS_NTSEC_BY_DEFAULT: case HAS_NTSEC_BY_DEFAULT:
return has_ntsec_by_default; return (has_ntsec_by_default);
} }
return 0; return (0);
} }
int check_nt_auth(int pwd_authenticated, struct passwd *pw) int
check_nt_auth(int pwd_authenticated, struct passwd *pw)
{ {
/* /*
* The only authentication which is able to change the user * The only authentication which is able to change the user
@ -155,28 +158,27 @@ int check_nt_auth(int pwd_authenticated, struct passwd *pw)
} }
if (has_create_token < 1 && if (has_create_token < 1 &&
!pwd_authenticated && geteuid() != pw->pw_uid) !pwd_authenticated && geteuid() != pw->pw_uid)
return 0; return (0);
} }
return 1; return (1);
} }
int check_ntsec(const char *filename) int
check_ntsec(const char *filename)
{ {
char *cygwin; char *cygwin;
int allow_ntea = 0; int allow_ntea = 0, allow_ntsec = 0;
int allow_ntsec = 0;
struct statfs fsstat; struct statfs fsstat;
/* Windows 95/98/ME don't support file system security at all. */ /* Windows 95/98/ME don't support file system security at all. */
if (!is_winnt) if (!is_winnt)
return 0; return (0);
/* Evaluate current CYGWIN settings. */ /* Evaluate current CYGWIN settings. */
cygwin = getenv("CYGWIN"); cygwin = getenv("CYGWIN");
allow_ntea = ntea_on(cygwin); allow_ntea = ntea_on(cygwin);
allow_ntsec = ntsec_on(cygwin) || allow_ntsec = ntsec_on(cygwin) ||
(has_capability(HAS_NTSEC_BY_DEFAULT) && (has_capability(HAS_NTSEC_BY_DEFAULT) && !ntsec_off(cygwin));
!ntsec_off(cygwin));
/* /*
* `ntea' is an emulation of POSIX attributes. It doesn't support * `ntea' is an emulation of POSIX attributes. It doesn't support
@ -185,14 +187,14 @@ int check_ntsec(const char *filename)
* for security checks. * for security checks.
*/ */
if (allow_ntea) if (allow_ntea)
return 1; return (1);
/* /*
* Retrieve file system flags. In Cygwin, file system flags are * Retrieve file system flags. In Cygwin, file system flags are
* copied to f_type which has no meaning in Win32 itself. * copied to f_type which has no meaning in Win32 itself.
*/ */
if (statfs(filename, &fsstat)) if (statfs(filename, &fsstat))
return 1; return (1);
/* /*
* Only file systems supporting ACLs are able to set permissions. * Only file systems supporting ACLs are able to set permissions.
@ -200,12 +202,13 @@ int check_ntsec(const char *filename)
* ACLs to support POSIX permissions on files. * ACLs to support POSIX permissions on files.
*/ */
if (fsstat.f_type & FS_PERSISTENT_ACLS) if (fsstat.f_type & FS_PERSISTENT_ACLS)
return allow_ntsec; return (allow_ntsec);
return 0; return (0);
} }
void register_9x_service(void) void
register_9x_service(void)
{ {
HINSTANCE kerneldll; HINSTANCE kerneldll;
DWORD (*RegisterServiceProcess)(DWORD, DWORD); DWORD (*RegisterServiceProcess)(DWORD, DWORD);

View File

@ -1,4 +1,4 @@
/* $Id: bsd-cygwin_util.h,v 1.7 2002/04/15 22:00:52 stevesk Exp $ */ /* $Id: bsd-cygwin_util.h,v 1.8 2003/05/18 14:13:39 djm Exp $ */
/* /*
* cygwin_util.c * cygwin_util.c
@ -38,10 +38,10 @@
#include <io.h> #include <io.h>
int binary_open(const char *filename, int flags, ...); int binary_open(const char *, int , ...);
int binary_pipe(int fd[2]); int binary_pipe(int fd[2]);
int check_nt_auth(int pwd_authenticated, struct passwd *pw); int check_nt_auth(int, struct passwd *);
int check_ntsec(const char *filename); int check_ntsec(const char *);
void register_9x_service(void); void register_9x_service(void);
#define open binary_open #define open binary_open

View File

@ -1,4 +1,28 @@
/* $Id: bsd-getpeereid.h,v 1.1 2002/09/12 00:33:02 djm Exp $ */ /*
* Copyright (c) 2002-2003 Damien Miller. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* $Id: bsd-getpeereid.h,v 1.2 2003/05/18 14:13:39 djm Exp $ */
#ifndef _BSD_GETPEEREID_H #ifndef _BSD_GETPEEREID_H
#define _BSD_GETPEEREID_H #define _BSD_GETPEEREID_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999-2000 Damien Miller. All rights reserved. * Copyright (c) 1999-2003 Damien Miller. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -25,7 +25,7 @@
#include "includes.h" #include "includes.h"
#include "xmalloc.h" #include "xmalloc.h"
RCSID("$Id: bsd-misc.c,v 1.12 2003/03/18 18:21:41 tim Exp $"); RCSID("$Id: bsd-misc.c,v 1.13 2003/05/18 14:13:39 djm Exp $");
/* /*
* NB. duplicate __progname in case it is an alias for argv[0] * NB. duplicate __progname in case it is an alias for argv[0]
@ -41,14 +41,14 @@ char *get_progname(char *argv0)
char *p; char *p;
if (argv0 == NULL) if (argv0 == NULL)
return "unknown"; /* XXX */ return ("unknown"); /* XXX */
p = strrchr(argv0, '/'); p = strrchr(argv0, '/');
if (p == NULL) if (p == NULL)
p = argv0; p = argv0;
else else
p++; p++;
return xstrdup(p); return (xstrdup(p));
#endif #endif
} }
@ -89,7 +89,7 @@ const char *strerror(int e)
if ((e >= 0) && (e < sys_nerr)) if ((e >= 0) && (e < sys_nerr))
return (sys_errlist[e]); return (sys_errlist[e]);
else
return ("unlisted error"); return ("unlisted error");
} }
#endif #endif
@ -113,13 +113,14 @@ int truncate (const char *path, off_t length)
fd = open(path, O_WRONLY); fd = open(path, O_WRONLY);
if (fd < 0) if (fd < 0)
return -1; return (-1);
ret = ftruncate(fd, length); ret = ftruncate(fd, length);
saverrno = errno; saverrno = errno;
(void) close (fd); close(fd);
if (ret == -1) if (ret == -1)
errno = saverrno; errno = saverrno;
return(ret); return(ret);
} }
#endif /* HAVE_TRUNCATE */ #endif /* HAVE_TRUNCATE */
@ -131,7 +132,7 @@ int truncate (const char *path, off_t length)
int int
setgroups(size_t size, const gid_t *list) setgroups(size_t size, const gid_t *list)
{ {
return 0; return (0);
} }
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999-2000 Damien Miller. All rights reserved. * Copyright (c) 1999-2003 Damien Miller. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -22,42 +22,41 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/* $Id: bsd-misc.h,v 1.7 2003/03/18 18:21:41 tim Exp $ */ /* $Id: bsd-misc.h,v 1.8 2003/05/18 14:13:39 djm Exp $ */
#ifndef _BSD_MISC_H #ifndef _BSD_MISC_H
#define _BSD_MISC_H #define _BSD_MISC_H
#include "config.h" #include "config.h"
char *get_progname(char *argv0); char *get_progname(char *);
#ifndef HAVE_SETSID #ifndef HAVE_SETSID
#define setsid() setpgrp(0, getpid()) #define setsid() setpgrp(0, getpid())
#endif /* !HAVE_SETSID */ #endif /* !HAVE_SETSID */
#ifndef HAVE_SETENV #ifndef HAVE_SETENV
int setenv(const char *name, const char *value, int overwrite); int setenv(const char *, const char *, int);
#endif /* !HAVE_SETENV */ #endif /* !HAVE_SETENV */
#ifndef HAVE_SETLOGIN #ifndef HAVE_SETLOGIN
int setlogin(const char *name); int setlogin(const char *);
#endif /* !HAVE_SETLOGIN */ #endif /* !HAVE_SETLOGIN */
#ifndef HAVE_INNETGR #ifndef HAVE_INNETGR
int innetgr(const char *netgroup, const char *host, int innetgr(const char *, const char *, const char *, const char *);
const char *user, const char *domain);
#endif /* HAVE_INNETGR */ #endif /* HAVE_INNETGR */
#if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) #if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID)
int seteuid(uid_t euid); int seteuid(uid_t);
#endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */ #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */
#if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID)
int setegid(uid_t egid); int setegid(uid_t);
#endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */ #endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */
#if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR) #if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR)
const char *strerror(int e); const char *strerror(int);
#endif #endif
@ -69,15 +68,15 @@ struct timeval {
} }
#endif /* HAVE_STRUCT_TIMEVAL */ #endif /* HAVE_STRUCT_TIMEVAL */
int utimes(char *filename, struct timeval *tvp); int utimes(char *, struct timeval *);
#endif /* HAVE_UTIMES */ #endif /* HAVE_UTIMES */
#ifndef HAVE_TRUNCATE #ifndef HAVE_TRUNCATE
int truncate (const char *path, off_t length); int truncate (const char *, off_t);
#endif /* HAVE_TRUNCATE */ #endif /* HAVE_TRUNCATE */
#if !defined(HAVE_SETGROUPS) && defined(SETGROUPS_NOOP) #if !defined(HAVE_SETGROUPS) && defined(SETGROUPS_NOOP)
int setgroups(size_t size, const gid_t *list); int setgroups(size_t, const gid_t *);
#endif #endif
#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) #if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
@ -87,7 +86,7 @@ struct timespec {
long tv_nsec; long tv_nsec;
}; };
#endif #endif
int nanosleep(const struct timespec *req, struct timespec *rem); int nanosleep(const struct timespec *, struct timespec *);
#endif #endif
#endif /* _BSD_MISC_H */ #endif /* _BSD_MISC_H */

View File

@ -1,3 +1,5 @@
/* XXX - author */
/* /*
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -22,7 +24,7 @@
#include "includes.h" #include "includes.h"
RCSID("$Id: bsd-nextstep.c,v 1.4 2001/03/26 05:35:34 mouring Exp $"); RCSID("$Id: bsd-nextstep.c,v 1.5 2003/05/18 14:13:39 djm Exp $");
#ifdef HAVE_NEXT #ifdef HAVE_NEXT
#include <errno.h> #include <errno.h>
@ -40,7 +42,7 @@ posix_wait(int *status)
if (status) if (status)
*status = (int) statusp.w_status; *status = (int) statusp.w_status;
return wait_pid; return (wait_pid);
} }
int int

View File

@ -1,3 +1,5 @@
/* XXX - author */
/* /*
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -21,7 +23,7 @@
* *
*/ */
/* $Id: bsd-nextstep.h,v 1.6 2001/03/19 13:42:22 mouring Exp $ */ /* $Id: bsd-nextstep.h,v 1.7 2003/05/18 14:13:39 djm Exp $ */
#ifndef _NEXT_POSIX_H #ifndef _NEXT_POSIX_H
#define _NEXT_POSIX_H #define _NEXT_POSIX_H
@ -37,22 +39,21 @@
#define dirent direct #define dirent direct
/* Swap out NeXT's BSD wait() for a more POSIX complient one */ /* Swap out NeXT's BSD wait() for a more POSIX complient one */
pid_t posix_wait(int *status); pid_t posix_wait(int *);
#define wait(a) posix_wait(a) #define wait(a) posix_wait(a)
/* #ifdef wrapped functions that need defining for clean compiling */ /* #ifdef wrapped functions that need defining for clean compiling */
pid_t getppid(void); pid_t getppid(void);
void vhangup(void); void vhangup(void);
int innetgr(const char *netgroup, const char *host, const char *user, int innetgr(const char *, const char *, const char *, const char *);
const char *domain);
/* TERMCAP */ /* TERMCAP */
int tcgetattr(int fd, struct termios *t); int tcgetattr(int, struct termios *);
int tcsetattr(int fd, int opt, const struct termios *t); int tcsetattr(int, int, const struct termios *);
int tcsetpgrp(int fd, pid_t pgrp); int tcsetpgrp(int, pid_t);
speed_t cfgetospeed(const struct termios *t); speed_t cfgetospeed(const struct termios *);
speed_t cfgetispeed(const struct termios *t); speed_t cfgetispeed(const struct termios *);
int cfsetospeed(struct termios *t, int speed); int cfsetospeed(struct termios *, int);
int cfsetispeed(struct termios *t, int speed); int cfsetispeed(struct termios *, int);
#endif /* HAVE_NEXT */ #endif /* HAVE_NEXT */
#endif /* _NEXT_POSIX_H */ #endif /* _NEXT_POSIX_H */

View File

@ -58,7 +58,7 @@
#include "includes.h" #include "includes.h"
RCSID("$Id: bsd-snprintf.c,v 1.6 2003/04/01 11:31:56 djm Exp $"); RCSID("$Id: bsd-snprintf.c,v 1.7 2003/05/18 14:13:39 djm Exp $");
#if defined(BROKEN_SNPRINTF) /* For those with broken snprintf() */ #if defined(BROKEN_SNPRINTF) /* For those with broken snprintf() */
# undef HAVE_SNPRINTF # undef HAVE_SNPRINTF
@ -121,15 +121,10 @@ dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
static void static void
dopr(char *buffer, size_t maxlen, const char *format, va_list args) dopr(char *buffer, size_t maxlen, const char *format, va_list args)
{ {
char *strvalue; char *strvalue, ch;
char ch;
long value; long value;
long double fvalue; long double fvalue;
int min = 0; int min = 0, max = -1, state = DP_S_DEFAULT, flags = 0, cflags = 0;
int max = -1;
int state = DP_S_DEFAULT;
int flags = 0;
int cflags = 0;
size_t currlen = 0; size_t currlen = 0;
ch = *format++; ch = *format++;
@ -369,8 +364,7 @@ static void
fmtstr(char *buffer, size_t *currlen, size_t maxlen, fmtstr(char *buffer, size_t *currlen, size_t maxlen,
char *value, int flags, int min, int max) char *value, int flags, int min, int max)
{ {
int padlen, strln; /* amount to pad */ int cnt = 0, padlen, strln; /* amount to pad */
int cnt = 0;
if (value == 0) if (value == 0)
value = "<NULL>"; value = "<NULL>";
@ -406,11 +400,9 @@ fmtint(char *buffer, size_t *currlen, size_t maxlen,
{ {
unsigned long uvalue; unsigned long uvalue;
char convert[20]; char convert[20];
int signvalue = 0; int signvalue = 0, place = 0, caps = 0;
int place = 0;
int spadlen = 0; /* amount to space pad */ int spadlen = 0; /* amount to space pad */
int zpadlen = 0; /* amount to zero pad */ int zpadlen = 0; /* amount to zero pad */
int caps = 0;
if (max < 0) if (max < 0)
max = 0; max = 0;
@ -429,7 +421,6 @@ fmtint(char *buffer, size_t *currlen, size_t maxlen,
if (flags & DP_F_UP) if (flags & DP_F_UP)
caps = 1; /* Should characters be upper case? */ caps = 1; /* Should characters be upper case? */
do { do {
convert[place++] = convert[place++] =
(caps ? "0123456789ABCDEF" : "0123456789abcdef") (caps ? "0123456789ABCDEF" : "0123456789abcdef")
@ -453,7 +444,6 @@ fmtint(char *buffer, size_t *currlen, size_t maxlen,
if (flags & DP_F_MINUS) if (flags & DP_F_MINUS)
spadlen = -spadlen; /* Left Justifty */ spadlen = -spadlen; /* Left Justifty */
/* Spaces */ /* Spaces */
while (spadlen > 0) { while (spadlen > 0) {
dopr_outch(buffer, currlen, maxlen, ' '); dopr_outch(buffer, currlen, maxlen, ' ');
@ -512,16 +502,11 @@ static void
fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue, fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue,
int min, int max, int flags) int min, int max, int flags)
{ {
char iconvert[20]; char iconvert[20], fconvert[20];
char fconvert[20]; int signvalue = 0, iplace = 0, fplace = 0;
int signvalue = 0;
int iplace = 0;
int fplace = 0;
int padlen = 0; /* amount to pad */ int padlen = 0; /* amount to pad */
int zpadlen = 0; int zpadlen = 0, caps = 0;
int caps = 0; long intpart, fracpart;
long intpart;
long fracpart;
long double ufvalue; long double ufvalue;
/* /*
@ -562,7 +547,8 @@ fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue,
/* Convert integer part */ /* Convert integer part */
do { do {
iconvert[iplace++] = iconvert[iplace++] =
(caps? "0123456789ABCDEF":"0123456789abcdef")[intpart % 10]; (caps ? "0123456789ABCDEF" : "0123456789abcdef")
[intpart % 10];
intpart = (intpart / 10); intpart = (intpart / 10);
} while(intpart && (iplace < 20)); } while(intpart && (iplace < 20));
if (iplace == 20) if (iplace == 20)
@ -572,7 +558,8 @@ fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue,
/* Convert fractional part */ /* Convert fractional part */
do { do {
fconvert[fplace++] = fconvert[fplace++] =
(caps? "0123456789ABCDEF":"0123456789abcdef")[fracpart % 10]; (caps ? "0123456789ABCDEF" : "0123456789abcdef")
[fracpart % 10];
fracpart = (fracpart / 10); fracpart = (fracpart / 10);
} while(fracpart && (fplace < 20)); } while(fracpart && (fplace < 20));
if (fplace == 20) if (fplace == 20)
@ -611,8 +598,8 @@ fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue,
dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]); dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]);
/* /*
* Decimal point. This should probably use locale to find the correct * Decimal point. This should probably use locale to find the
* char to print out. * correct char to print out.
*/ */
dopr_outch(buffer, currlen, maxlen, '.'); dopr_outch(buffer, currlen, maxlen, '.');
@ -662,90 +649,4 @@ snprintf(char *str,size_t count,const char *fmt,...)
return(strlen(str)); return(strlen(str));
} }
#ifdef TEST_SNPRINTF
int
main(void)
{
#define LONG_STRING 1024
char buf1[LONG_STRING];
char buf2[LONG_STRING];
char *fp_fmt[] = {
"%-1.5f",
"%1.5f",
"%123.9f",
"%10.5f",
"% 10.5f",
"%+22.9f",
"%+4.9f",
"%01.3f",
"%4f",
"%3.1f",
"%3.2f",
NULL
};
double fp_nums[] = {
-1.5,
134.21,
91340.2,
341.1234,
0203.9,
0.96,
0.996,
0.9996,
1.996,
4.136,
0
};
char *int_fmt[] = {
"%-1.5d",
"%1.5d",
"%123.9d",
"%5.5d",
"%10.5d",
"% 10.5d",
"%+22.33d",
"%01.3d",
"%4d",
"%lld",
"%qd",
NULL
};
long long int_nums[] = { -1, 134, 91340, 341, 0203, 0, 9999999 };
int x, y;
int fail = 0;
int num = 0;
printf("Testing snprintf format codes against system sprintf...\n");
for (x = 0; fp_fmt[x] != NULL ; x++) {
for (y = 0; fp_nums[y] != 0 ; y++) {
snprintf(buf1, sizeof (buf1), fp_fmt[x], fp_nums[y]);
sprintf (buf2, fp_fmt[x], fp_nums[y]);
if (strcmp (buf1, buf2)) {
printf("snprintf doesn't match Format: %s\n\t"
"snprintf = %s\n\tsprintf = %s\n",
fp_fmt[x], buf1, buf2);
fail++;
}
num++;
}
}
for (x = 0; int_fmt[x] != NULL ; x++) {
for (y = 0; int_nums[y] != 0 ; y++) {
snprintf(buf1, sizeof (buf1), int_fmt[x], int_nums[y]);
sprintf(buf2, int_fmt[x], int_nums[y]);
if (strcmp (buf1, buf2)) {
printf("snprintf doesn't match Format: %s\n\t"
"snprintf = %s\n\tsprintf = %s\n",
int_fmt[x], buf1, buf2);
fail++;
}
num++;
}
}
printf("%d tests failed out of %d.\n", fail, num);
return(0);
}
#endif /* SNPRINTF_TEST */
#endif /* !HAVE_SNPRINTF */ #endif /* !HAVE_SNPRINTF */

View File

@ -1,4 +1,4 @@
/* $Id: bsd-snprintf.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */ /* $Id: bsd-snprintf.h,v 1.3 2003/05/18 14:13:39 djm Exp $ */
#ifndef _BSD_SNPRINTF_H #ifndef _BSD_SNPRINTF_H
#define _BSD_SNPRINTF_H #define _BSD_SNPRINTF_H
@ -8,11 +8,11 @@
#include <sys/types.h> /* For size_t */ #include <sys/types.h> /* For size_t */
#ifndef HAVE_SNPRINTF #ifndef HAVE_SNPRINTF
int snprintf(char *str, size_t count, const char *fmt, ...); int snprintf(char *, size_t, const char *, ...);
#endif /* !HAVE_SNPRINTF */ #endif /* !HAVE_SNPRINTF */
#ifndef HAVE_VSNPRINTF #ifndef HAVE_VSNPRINTF
int vsnprintf(char *str, size_t count, const char *fmt, va_list args); int vsnprintf(char *, size_t, const char *, va_list);
#endif /* !HAVE_SNPRINTF */ #endif /* !HAVE_SNPRINTF */

View File

@ -1,3 +1,5 @@
/* XXX - no author */
/* /*
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -22,7 +24,7 @@
#include "includes.h" #include "includes.h"
RCSID("$Id: bsd-waitpid.c,v 1.3 2001/03/26 05:35:34 mouring Exp $"); RCSID("$Id: bsd-waitpid.c,v 1.4 2003/05/18 14:13:39 djm Exp $");
#ifndef HAVE_WAITPID #ifndef HAVE_WAITPID
#include <errno.h> #include <errno.h>
@ -38,15 +40,16 @@ waitpid(int pid, int *stat_loc, int options)
if (pid <= 0) { if (pid <= 0) {
if (pid != -1) { if (pid != -1) {
errno = EINVAL; errno = EINVAL;
return -1; return (-1);
} }
pid = 0; /* wait4() wants pid=0 for indiscriminate wait. */ /* wait4() wants pid=0 for indiscriminate wait. */
pid = 0;
} }
wait_pid = wait4(pid, &statusp, options, NULL); wait_pid = wait4(pid, &statusp, options, NULL);
if (stat_loc) if (stat_loc)
*stat_loc = (int) statusp.w_status; *stat_loc = (int) statusp.w_status;
return wait_pid; return (wait_pid);
} }
#endif /* !HAVE_WAITPID */ #endif /* !HAVE_WAITPID */

View File

@ -21,7 +21,7 @@
* *
*/ */
/* $Id: bsd-waitpid.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */ /* $Id: bsd-waitpid.h,v 1.3 2003/05/18 14:13:39 djm Exp $ */
#ifndef _BSD_WAITPID_H #ifndef _BSD_WAITPID_H
#define _BSD_WAITPID_H #define _BSD_WAITPID_H
@ -43,7 +43,7 @@
#define WCOREDUMP(w) ((_W_INT(w)) & WCOREFLAG) #define WCOREDUMP(w) ((_W_INT(w)) & WCOREFLAG)
/* Prototype */ /* Prototype */
pid_t waitpid(int pid, int *stat_loc, int options); pid_t waitpid(int, int *, int);
#endif /* !HAVE_WAITPID */ #endif /* !HAVE_WAITPID */
#endif /* _BSD_WAITPID_H */ #endif /* _BSD_WAITPID_H */

View File

@ -5,10 +5,15 @@
* See getaddrinfo.c and getnameinfo.c. * See getaddrinfo.c and getnameinfo.c.
*/ */
/* $Id: fake-gai-errnos.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */ #ifndef _FAKE_GAI_ERRNOS_H
#define _FAKE_GAI_ERRNOS_H
/* $Id: fake-gai-errnos.h,v 1.3 2003/05/18 14:13:39 djm Exp $ */
/* for old netdb.h */ /* for old netdb.h */
#ifndef EAI_NODATA #ifndef EAI_NODATA
# define EAI_NODATA 1 # define EAI_NODATA 1
# define EAI_MEMORY 2 # define EAI_MEMORY 2
#endif #endif
#endif /* !_FAKE_GAI_ERRNOS_H */

View File

@ -10,47 +10,48 @@
*/ */
#include "includes.h" #include "includes.h"
#include "xmalloc.h"
#include "ssh.h" #include "ssh.h"
RCSID("$Id: fake-getaddrinfo.c,v 1.6 2003/05/14 11:48:51 dtucker Exp $"); RCSID("$Id: fake-getaddrinfo.c,v 1.7 2003/05/18 14:13:39 djm Exp $");
#ifndef HAVE_GAI_STRERROR #ifndef HAVE_GAI_STRERROR
char *gai_strerror(int ecode) char *
gai_strerror(int err)
{ {
switch (ecode) { switch (err) {
case EAI_NODATA: case EAI_NODATA:
return "no address associated with hostname."; return ("no address associated with name");
case EAI_MEMORY: case EAI_MEMORY:
return "memory allocation failure."; return ("memory allocation failure.");
default: default:
return "unknown error."; return ("unknown/invalid error.");
} }
} }
#endif /* !HAVE_GAI_STRERROR */ #endif /* !HAVE_GAI_STRERROR */
#ifndef HAVE_FREEADDRINFO #ifndef HAVE_FREEADDRINFO
void freeaddrinfo(struct addrinfo *ai) void
freeaddrinfo(struct addrinfo *ai)
{ {
struct addrinfo *next; struct addrinfo *next;
do { for(;ai != NULL; next = ai->ai_next) {
next = ai->ai_next;
free(ai); free(ai);
} while (NULL != (ai = next)); ai = next;
}
} }
#endif /* !HAVE_FREEADDRINFO */ #endif /* !HAVE_FREEADDRINFO */
#ifndef HAVE_GETADDRINFO #ifndef HAVE_GETADDRINFO
static struct addrinfo *malloc_ai(int port, u_long addr, static struct
const struct addrinfo *hints) addrinfo *malloc_ai(int port, u_long addr, const struct addrinfo *hints)
{ {
struct addrinfo *ai; struct addrinfo *ai;
ai = malloc(sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); ai = xmalloc(sizeof(*ai) + sizeof(struct sockaddr_in));
if (ai == NULL)
return(NULL);
memset(ai, 0, sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); memset(ai, '\0', sizeof(*ai) + sizeof(struct sockaddr_in));
ai->ai_addr = (struct sockaddr *)(ai + 1); ai->ai_addr = (struct sockaddr *)(ai + 1);
/* XXX -- ssh doesn't use sa_len */ /* XXX -- ssh doesn't use sa_len */
@ -72,10 +73,10 @@ static struct addrinfo *malloc_ai(int port, u_long addr,
return (ai); return (ai);
} }
int getaddrinfo(const char *hostname, const char *servname, int
getaddrinfo(const char *hostname, const char *servname,
const struct addrinfo *hints, struct addrinfo **res) const struct addrinfo *hints, struct addrinfo **res)
{ {
struct addrinfo *cur, *prev = NULL;
struct hostent *hp; struct hostent *hp;
struct servent *sp; struct servent *sp;
struct in_addr in; struct in_addr in;
@ -100,37 +101,29 @@ int getaddrinfo(const char *hostname, const char *servname,
addr = htonl(0x00000000); addr = htonl(0x00000000);
if (hostname && inet_aton(hostname, &in) != 0) if (hostname && inet_aton(hostname, &in) != 0)
addr = in.s_addr; addr = in.s_addr;
if (NULL != (*res = malloc_ai(port, addr, hints))) *res = malloc_ai(port, addr, hints);
return 0; return (0);
else
return EAI_MEMORY;
} }
if (!hostname) { if (!hostname) {
if (NULL != (*res = malloc_ai(port, htonl(0x7f000001), hints))) *res = malloc_ai(port, htonl(0x7f000001), hints);
return 0; return (0);
else
return EAI_MEMORY;
} }
if (inet_aton(hostname, &in)) { if (inet_aton(hostname, &in)) {
if (NULL != (*res = malloc_ai(port, in.s_addr, hints))) *res = malloc_ai(port, in.s_addr, hints);
return 0; return (0);
else
return EAI_MEMORY;
} }
hp = gethostbyname(hostname); hp = gethostbyname(hostname);
if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) { if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) {
for (i = 0; hp->h_addr_list[i]; i++) { struct addrinfo *cur, *prev;
cur = malloc_ai(port,
((struct in_addr *)hp->h_addr_list[i])->s_addr, hints);
if (cur == NULL) {
if (*res)
freeaddrinfo(*res);
return EAI_MEMORY;
}
cur = prev = NULL;
for (i = 0; hp->h_addr_list[i]; i++) {
struct in_addr *in = (struct in_addr *)hp->h_addr_list[i];
cur = malloc_ai(port, in->s_addr, hints);
if (prev) if (prev)
prev->ai_next = cur; prev->ai_next = cur;
else else
@ -138,9 +131,9 @@ int getaddrinfo(const char *hostname, const char *servname,
prev = cur; prev = cur;
} }
return 0; return (0);
} }
return EAI_NODATA; return (EAI_NODATA);
} }
#endif /* !HAVE_GETADDRINFO */ #endif /* !HAVE_GETADDRINFO */

View File

@ -12,7 +12,7 @@
#include "includes.h" #include "includes.h"
#include "ssh.h" #include "ssh.h"
RCSID("$Id: fake-getnameinfo.c,v 1.2 2001/02/09 01:55:36 djm Exp $"); RCSID("$Id: fake-getnameinfo.c,v 1.3 2003/05/18 14:13:39 djm Exp $");
#ifndef HAVE_GETNAMEINFO #ifndef HAVE_GETNAMEINFO
int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
@ -22,34 +22,31 @@ int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
struct hostent *hp; struct hostent *hp;
char tmpserv[16]; char tmpserv[16];
if (serv) { if (serv != NULL) {
snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port)); snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
if (strlen(tmpserv) >= servlen) if (strlcpy(serv, tmpserv, servlen) >= servlen)
return EAI_MEMORY; return (EAI_MEMORY);
else
strcpy(serv, tmpserv);
} }
if (host) { if (host != NULL) {
if (flags & NI_NUMERICHOST) { if (flags & NI_NUMERICHOST) {
if (strlen(inet_ntoa(sin->sin_addr)) >= hostlen) if (strlcpy(host, inet_ntoa(sin->sin_addr),
return EAI_MEMORY; hostlen) >= hostlen)
return (EAI_MEMORY);
strcpy(host, inet_ntoa(sin->sin_addr)); else
return 0; return (0);
} else { } else {
hp = gethostbyaddr((char *)&sin->sin_addr, hp = gethostbyaddr((char *)&sin->sin_addr,
sizeof(struct in_addr), AF_INET); sizeof(struct in_addr), AF_INET);
if (hp == NULL) if (hp == NULL)
return EAI_NODATA; return (EAI_NODATA);
if (strlen(hp->h_name) >= hostlen) if (strlcpy(host, hp->h_name, hostlen) >= hostlen)
return EAI_MEMORY; return (EAI_MEMORY);
else
strcpy(host, hp->h_name); return (0);
return 0;
} }
} }
return 0; return (0);
} }
#endif /* !HAVE_GETNAMEINFO */ #endif /* !HAVE_GETNAMEINFO */

View File

@ -1,4 +1,4 @@
/* $Id: fake-getnameinfo.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */ /* $Id: fake-getnameinfo.h,v 1.3 2003/05/18 14:13:39 djm Exp $ */
#ifndef _FAKE_GETNAMEINFO_H #ifndef _FAKE_GETNAMEINFO_H
#define _FAKE_GETNAMEINFO_H #define _FAKE_GETNAMEINFO_H
@ -6,8 +6,8 @@
#include "config.h" #include "config.h"
#ifndef HAVE_GETNAMEINFO #ifndef HAVE_GETNAMEINFO
int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, int getnameinfo(const struct sockaddr *, size_t, char *, size_t,
size_t hostlen, char *serv, size_t servlen, int flags); char *, size_t, int);
#endif /* !HAVE_GETNAMEINFO */ #endif /* !HAVE_GETNAMEINFO */
#ifndef NI_MAXSERV #ifndef NI_MAXSERV

View File

@ -46,14 +46,18 @@ void
aix_usrinfo(struct passwd *pw) aix_usrinfo(struct passwd *pw)
{ {
u_int i; u_int i;
size_t len;
char *cp; char *cp;
cp = xmalloc(16 + 2 * strlen(pw->pw_name)); len = sizeof("LOGNAME= NAME= ") + (2 * strlen(pw->pw_name));
i = sprintf(cp, "LOGNAME=%s%cNAME=%s%c", pw->pw_name, 0, cp = xmalloc(len);
pw->pw_name, 0);
i = snprintf(cp, "LOGNAME=%s%cNAME=%s%c", pw->pw_name, '\0',
pw->pw_name, '\0', len);
if (usrinfo(SETUINFO, cp, i) == -1) if (usrinfo(SETUINFO, cp, i) == -1)
fatal("Couldn't set usrinfo: %s", strerror(errno)); fatal("Couldn't set usrinfo: %s", strerror(errno));
debug3("AIX/UsrInfo: set len %d", i); debug3("AIX/UsrInfo: set len %d", i);
xfree(cp); xfree(cp);
} }
@ -64,8 +68,9 @@ aix_usrinfo(struct passwd *pw)
void void
record_failed_login(const char *user, const char *ttyname) record_failed_login(const char *user, const char *ttyname)
{ {
loginfailed(user, char *hostname = get_canonical_hostname(options.verify_reverse_mapping);
get_canonical_hostname(options.verify_reverse_mapping), ttyname);
loginfailed(user, hostname, ttyname);
} }
# endif /* CUSTOM_FAILED_LOGIN */ # endif /* CUSTOM_FAILED_LOGIN */
#endif /* _AIX */ #endif /* _AIX */

View File

@ -1,6 +1,10 @@
/* XXX - BSD license here */
#include "includes.h" #include "includes.h"
#if defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) #if defined(WITH_IRIX_PROJECT) || \
defined(WITH_IRIX_JOBS) || \
defined(WITH_IRIX_ARRAY)
#ifdef WITH_IRIX_PROJECT #ifdef WITH_IRIX_PROJECT
# include <proj.h> # include <proj.h>
@ -17,14 +21,12 @@ irix_setusercontext(struct passwd *pw)
{ {
#ifdef WITH_IRIX_PROJECT #ifdef WITH_IRIX_PROJECT
prid_t projid; prid_t projid;
#endif /* WITH_IRIX_PROJECT */ #endif
#ifdef WITH_IRIX_JOBS #ifdef WITH_IRIX_JOBS
jid_t jid = 0; jid_t jid = 0;
#else #elif defined(WITH_IRIX_ARRAY)
# ifdef WITH_IRIX_ARRAY
int jid = 0; int jid = 0;
# endif /* WITH_IRIX_ARRAY */ #endif
#endif /* WITH_IRIX_JOBS */
#ifdef WITH_IRIX_JOBS #ifdef WITH_IRIX_JOBS
jid = jlimit_startjob(pw->pw_name, pw->pw_uid, "interactive"); jid = jlimit_startjob(pw->pw_name, pw->pw_uid, "interactive");

View File

@ -1,5 +1,14 @@
#if defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) /* XXX - BSD license */
#ifndef _PORT_IRIX_H
#define _PORT_IRIX_H
#if defined(WITH_IRIX_PROJECT) || \
defined(WITH_IRIX_JOBS) || \
defined(WITH_IRIX_ARRAY)
void irix_setusercontext(struct passwd *pw); void irix_setusercontext(struct passwd *pw);
#endif /* defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) */ #endif /* defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) */
#endif /* ! _PORT_IRIX_H */

View File

@ -38,6 +38,7 @@ static char rcsid[] = "$OpenBSD: vis.c,v 1.11 2003/05/14 05:16:43 pjanzen Exp $"
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <ctype.h> #include <ctype.h>
#include <string.h>
#include "vis.h" #include "vis.h"