From c274551db67a3002f12afa127c32509ae194e3e5 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Thu, 3 Sep 2009 20:54:39 +0000 Subject: [PATCH] - Make it compile on operating systems other than BSD due to OpenBSD patchset 308. - While there, remove some duplicate code from the compat header file. --- compat.h | 61 ++++++++--------------------------------------------- configure | 6 +++++- server-fn.c | 10 +++++++-- 3 files changed, 22 insertions(+), 55 deletions(-) diff --git a/compat.h b/compat.h index addf43d8..a6265d73 100644 --- a/compat.h +++ b/compat.h @@ -1,4 +1,4 @@ -/* $Id: compat.h,v 1.16 2009-09-02 12:30:56 nicm Exp $ */ +/* $Id: compat.h,v 1.17 2009-09-03 20:54:39 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -91,6 +91,10 @@ typedef uint64_t u_int64_t; #include "compat/imsg.h" #endif +#ifdef HAVE_LOGIN_CAP +#include +#endif + #ifdef HAVE_BROKEN_CMSG_FIRSTHDR /* Broken on OS X. */ #undef CMSG_FIRSTHDR @@ -146,6 +150,10 @@ typedef uint64_t u_int64_t; #define TTY_NAME_MAX 32 #endif +#ifndef _PW_BUF_LEN +#define _PW_BUF_LEN 1024 +#endif + #ifndef HAVE_BZERO #define bzero(buf, len) memset((buf), 0, (len)); #endif @@ -211,54 +219,3 @@ int BSDgetopt(int, char *const *, const char *); #define optreset BSDoptreset #define optarg BSDoptarg #endif -#ifndef HAVE_STRTONUM -/* strtonum.c */ -long long strtonum(const char *, long long, long long, const char **); -#endif - -#ifndef HAVE_STRLCPY -/* strlcpy.c */ -size_t strlcpy(char *, const char *, size_t); -#endif - -#ifndef HAVE_STRLCAT -/* strlcat.c */ -size_t strlcat(char *, const char *, size_t); -#endif - -#ifndef HAVE_DAEMON -/* daemon.c */ -int daemon(int, int); -#endif - -#ifndef HAVE_FORKPTY -/* forkpty.c */ -pid_t forkpty(int *, char *, struct termios *, struct winsize *); -#endif - -#ifndef HAVE_ASPRINTF -/* asprintf.c */ -int asprintf(char **, const char *, ...); -int vasprintf(char **, const char *, va_list); -#endif - -#ifndef HAVE_FGETLN -/* fgetln.c */ -char *fgetln(FILE *, size_t *); -#endif - -#ifndef HAVE_GETOPT -/* getopt.c */ -extern int BSDopterr; -extern int BSDoptind; -extern int BSDoptopt; -extern int BSDoptreset; -extern char *BSDoptarg; -int BSDgetopt(int, char *const *, const char *); -#define getopt(ac, av, o) BSDgetopt(ac, av, o) -#define opterr BSDopterr -#define optind BSDoptind -#define optopt BSDoptopt -#define optreset BSDoptreset -#define optarg BSDoptarg -#endif diff --git a/configure b/configure index f16bd222..7b9d51cb 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #!/bin/sh -# $Id: configure,v 1.34 2009-09-02 12:30:56 nicm Exp $ +# $Id: configure,v 1.35 2009-09-03 20:54:39 tcunha Exp $ TMUX_PLATFORM=${TMUX_PLATFORM:-`uname -s`} @@ -22,6 +22,7 @@ cat <>$CONFIG_H #undef HAVE_GETOPT #undef HAVE_IMSG #undef HAVE_LIBUTIL_H +#undef HAVE_LOGIN_CAP #undef HAVE_PATHS_H #undef HAVE_POLL #undef HAVE_PROGNAME @@ -52,6 +53,7 @@ case $TMUX_PLATFORM in #define HAVE_FGETLN #define HAVE_FORKPTY #define HAVE_GETOPT +#define HAVE_LOGIN_CAP #define HAVE_PATHS_H #define HAVE_POLL #define HAVE_PROGNAME @@ -207,6 +209,7 @@ EOF #define HAVE_FORKPTY #define HAVE_GETOPT #define HAVE_LIBUTIL_H +#define HAVE_LOGIN_CAP #define HAVE_PATHS_H #define HAVE_POLL #define HAVE_PROGNAME @@ -238,6 +241,7 @@ EOF #define HAVE_FGETLN #define HAVE_FORKPTY #define HAVE_GETOPT +#define HAVE_LOGIN_CAP #define HAVE_PATHS_H #define HAVE_POLL #define HAVE_PROGNAME diff --git a/server-fn.c b/server-fn.c index b0ea65ae..2390236b 100644 --- a/server-fn.c +++ b/server-fn.c @@ -1,4 +1,4 @@ -/* $Id: server-fn.c,v 1.84 2009-09-03 20:44:38 tcunha Exp $ */ +/* $Id: server-fn.c,v 1.85 2009-09-03 20:54:39 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -18,7 +18,6 @@ #include -#include #include #include #include @@ -199,7 +198,9 @@ int server_unlock(const char *s) { struct client *c; +#ifdef HAVE_LOGIN_CAP login_cap_t *lc; +#endif u_int i; char *out; u_int failures, tries, backoff; @@ -250,6 +251,7 @@ wrong: * Start slowing down after "login-backoff" attempts and reset every * "login-tries" attempts. */ +#ifdef HAVE_LOGIN_CAP lc = login_getclass(server_locked_pw->pw_class); if (lc != NULL) { tries = login_getcapnum(lc, (char *) "login-tries", 10, 10); @@ -258,6 +260,10 @@ wrong: tries = 10; backoff = 3; } +#else + tries = 10; + backoff = 3; +#endif failures = password_failures % tries; if (failures > backoff) { password_backoff += ((failures - backoff) * tries / 2);