summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/openbsd-compat.h3
-rw-r--r--openbsd-compat/port-aix.c122
-rw-r--r--openbsd-compat/port-aix.h10
-rw-r--r--session.c111
6 files changed, 142 insertions, 115 deletions
diff --git a/ChangeLog b/ChangeLog
index 5944e0adb..a7ef8510f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -43,8 +43,11 @@
43 - deraadt@cvs.openbsd.org 2002/02/19 02:50:59 43 - deraadt@cvs.openbsd.org 2002/02/19 02:50:59
44 [sshd_config] 44 [sshd_config]
45 stategy is not an english word 45 stategy is not an english word
46 - (bal) Migrate IRIX jobs/projects/audit/etc code to 46 - (bal) Migrated IRIX jobs/projects/audit/etc code to
47 openbsd-compat/port-irix.[ch] to improve readiblity of do_child() 47 openbsd-compat/port-irix.[ch] to improve readiblity of do_child()
48 - (bal) Migrated AIX getuserattr and usrinfo code to
49 openbsd-compat/port-aix.[c] to improve readilbity of do_child() and
50 simplify our diffs against upstream source.
48 51
4920020218 5220020218
50 - (tim) newer config.guess from ftp://ftp.gnu.org/gnu/config/config.guess 53 - (tim) newer config.guess from ftp://ftp.gnu.org/gnu/config/config.guess
@@ -7642,4 +7645,4 @@
7642 - Wrote replacements for strlcpy and mkdtemp 7645 - Wrote replacements for strlcpy and mkdtemp
7643 - Released 1.0pre1 7646 - Released 1.0pre1
7644 7647
7645$Id: ChangeLog,v 1.1866 2002/02/19 20:02:48 mouring Exp $ 7648$Id: ChangeLog,v 1.1867 2002/02/19 20:27:55 mouring Exp $
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index eac0abd5f..3e09cfefe 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.20 2002/02/19 20:02:49 mouring Exp $ 1# $Id: Makefile.in,v 1.21 2002/02/19 20:27:57 mouring Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -20,7 +20,7 @@ OPENBSD=base64.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getop
20 20
21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o 21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o
22 22
23PORTS=port-irix.o 23PORTS=port-irix.o port-aix.o
24 24
25.c.o: 25.c.o:
26 $(CC) $(CFLAGS) $(CPPFLAGS) -c $< 26 $(CC) $(CFLAGS) $(CPPFLAGS) -c $<
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 224055c25..11918443d 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.15 2002/02/19 20:02:49 mouring Exp $ */ 1/* $Id: openbsd-compat.h,v 1.16 2002/02/19 20:27:57 mouring Exp $ */
2 2
3#ifndef _OPENBSD_H 3#ifndef _OPENBSD_H
4#define _OPENBSD_H 4#define _OPENBSD_H
@@ -41,5 +41,6 @@
41/* Routines for a single OS platform */ 41/* Routines for a single OS platform */
42#include "bsd-cray.h" 42#include "bsd-cray.h"
43#include "port-irix.h" 43#include "port-irix.h"
44#include "port-aix.h"
44 45
45#endif /* _OPENBSD_H */ 46#endif /* _OPENBSD_H */
diff --git a/openbsd-compat/port-aix.c b/openbsd-compat/port-aix.c
new file mode 100644
index 000000000..245c8a509
--- /dev/null
+++ b/openbsd-compat/port-aix.c
@@ -0,0 +1,122 @@
1#include "includes.h"
2
3#ifdef _AIX
4
5#include <uinfo.h>
6
7/* AIX limits */
8#if defined(HAVE_GETUSERATTR) && !defined(S_UFSIZE_HARD) && defined(S_UFSIZE)
9# define S_UFSIZE_HARD S_UFSIZE "_hard"
10# define S_UCPU_HARD S_UCPU "_hard"
11# define S_UDATA_HARD S_UDATA "_hard"
12# define S_USTACK_HARD S_USTACK "_hard"
13# define S_URSS_HARD S_URSS "_hard"
14# define S_UCORE_HARD S_UCORE "_hard"
15# define S_UNOFILE_HARD S_UNOFILE "_hard"
16#endif
17
18#if defined(HAVE_GETUSERATTR)
19/*
20 * AIX-specific login initialisation
21 */
22void
23set_limit(char *user, char *soft, char *hard, int resource, int mult)
24{
25 struct rlimit rlim;
26 int slim, hlim;
27
28 getrlimit(resource, &rlim);
29
30 slim = 0;
31 if (getuserattr(user, soft, &slim, SEC_INT) != -1) {
32 if (slim < 0) {
33 rlim.rlim_cur = RLIM_INFINITY;
34 } else if (slim != 0) {
35 /* See the wackiness below */
36 if (rlim.rlim_cur == slim * mult)
37 slim = 0;
38 else
39 rlim.rlim_cur = slim * mult;
40 }
41 }
42 hlim = 0;
43 if (getuserattr(user, hard, &hlim, SEC_INT) != -1) {
44 if (hlim < 0) {
45 rlim.rlim_max = RLIM_INFINITY;
46 } else if (hlim != 0) {
47 rlim.rlim_max = hlim * mult;
48 }
49 }
50
51 /*
52 * XXX For cpu and fsize the soft limit is set to the hard limit
53 * if the hard limit is left at its default value and the soft limit
54 * is changed from its default value, either by requesting it
55 * (slim == 0) or by setting it to the current default. At least
56 * that's how rlogind does it. If you're confused you're not alone.
57 * Bug or feature? AIX 4.3.1.2
58 */
59 if ((!strcmp(soft, "fsize") || !strcmp(soft, "cpu"))
60 && hlim == 0 && slim != 0)
61 rlim.rlim_max = rlim.rlim_cur;
62 /* A specified hard limit limits the soft limit */
63 else if (hlim > 0 && rlim.rlim_cur > rlim.rlim_max)
64 rlim.rlim_cur = rlim.rlim_max;
65 /* A soft limit can increase a hard limit */
66 else if (rlim.rlim_cur > rlim.rlim_max)
67 rlim.rlim_max = rlim.rlim_cur;
68
69 if (setrlimit(resource, &rlim) != 0)
70 error("setrlimit(%.10s) failed: %.100s", soft, strerror(errno));
71}
72
73void
74set_limits_from_userattr(char *user)
75{
76 int mask;
77 char buf[16];
78
79 set_limit(user, S_UFSIZE, S_UFSIZE_HARD, RLIMIT_FSIZE, 512);
80 set_limit(user, S_UCPU, S_UCPU_HARD, RLIMIT_CPU, 1);
81 set_limit(user, S_UDATA, S_UDATA_HARD, RLIMIT_DATA, 512);
82 set_limit(user, S_USTACK, S_USTACK_HARD, RLIMIT_STACK, 512);
83 set_limit(user, S_URSS, S_URSS_HARD, RLIMIT_RSS, 512);
84 set_limit(user, S_UCORE, S_UCORE_HARD, RLIMIT_CORE, 512);
85#if defined(S_UNOFILE)
86 set_limit(user, S_UNOFILE, S_UNOFILE_HARD, RLIMIT_NOFILE, 1);
87#endif
88
89 if (getuserattr(user, S_UMASK, &mask, SEC_INT) != -1) {
90 /* Convert decimal to octal */
91 (void) snprintf(buf, sizeof(buf), "%d", mask);
92 if (sscanf(buf, "%o", &mask) == 1)
93 umask(mask);
94 }
95}
96#endif /* defined(HAVE_GETUSERATTR) */
97
98/*
99 * AIX has a "usrinfo" area where logname and
100 * other stuff is stored - a few applications
101 * actually use this and die if it's not set
102 */
103void
104aix_usrinfo(Session *s)
105{
106 struct passwd *pw = s->pw;
107 u_int i;
108 const char *cp=NULL;
109
110 if (s->ttyfd == -1)
111 s->tty[0] = '\0';
112 cp = xmalloc(22 + strlen(s->tty) + 2 * strlen(pw->pw_name));
113 i = sprintf(cp, "LOGNAME=%s%cNAME=%s%cTTY=%s%c%c", pw->pw_name, 0,
114 pw->pw_name, 0, s->tty, 0, 0);
115 if (usrinfo(SETUINFO, cp, i) == -1)
116 fatal("Couldn't set usrinfo: %s", strerror(errno));
117 debug3("AIX/UsrInfo: set len %d", i);
118 xfree(cp);
119}
120
121#endif /* _AIX */
122
diff --git a/openbsd-compat/port-aix.h b/openbsd-compat/port-aix.h
new file mode 100644
index 000000000..891b27add
--- /dev/null
+++ b/openbsd-compat/port-aix.h
@@ -0,0 +1,10 @@
1#ifdef _AIX
2
3#ifdef HAVE_GETUSERATTR
4void set_limit(char *user, char *soft, char *hard, int resource, int mult);
5void set_limits_from_userattr(char *user);
6#endif /* HAVE_GETUSERATTR */
7
8void aix_usrinfo(Session *s);
9
10#endif /* _AIX */
diff --git a/session.c b/session.c
index e48c3c0b4..2134d917a 100644
--- a/session.c
+++ b/session.c
@@ -67,21 +67,6 @@ RCSID("$OpenBSD: session.c,v 1.126 2002/02/14 23:28:00 markus Exp $");
67#define is_winnt (GetVersion() < 0x80000000) 67#define is_winnt (GetVersion() < 0x80000000)
68#endif 68#endif
69 69
70/* AIX limits */
71#if defined(HAVE_GETUSERATTR) && !defined(S_UFSIZE_HARD) && defined(S_UFSIZE)
72# define S_UFSIZE_HARD S_UFSIZE "_hard"
73# define S_UCPU_HARD S_UCPU "_hard"
74# define S_UDATA_HARD S_UDATA "_hard"
75# define S_USTACK_HARD S_USTACK "_hard"
76# define S_URSS_HARD S_URSS "_hard"
77# define S_UCORE_HARD S_UCORE "_hard"
78# define S_UNOFILE_HARD S_UNOFILE "_hard"
79#endif
80
81#ifdef _AIX
82# include <uinfo.h>
83#endif
84
85/* types */ 70/* types */
86 71
87#define TTYSZ 64 72#define TTYSZ 64
@@ -898,85 +883,6 @@ void copy_environment(char **source, char ***env, u_int *envsize)
898 } 883 }
899} 884}
900 885
901#if defined(HAVE_GETUSERATTR)
902/*
903 * AIX-specific login initialisation
904 */
905void set_limit(char *user, char *soft, char *hard, int resource, int mult)
906{
907 struct rlimit rlim;
908 int slim, hlim;
909
910 getrlimit(resource, &rlim);
911
912 slim = 0;
913 if (getuserattr(user, soft, &slim, SEC_INT) != -1) {
914 if (slim < 0) {
915 rlim.rlim_cur = RLIM_INFINITY;
916 } else if (slim != 0) {
917 /* See the wackiness below */
918 if (rlim.rlim_cur == slim * mult)
919 slim = 0;
920 else
921 rlim.rlim_cur = slim * mult;
922 }
923 }
924
925 hlim = 0;
926 if (getuserattr(user, hard, &hlim, SEC_INT) != -1) {
927 if (hlim < 0) {
928 rlim.rlim_max = RLIM_INFINITY;
929 } else if (hlim != 0) {
930 rlim.rlim_max = hlim * mult;
931 }
932 }
933
934 /*
935 * XXX For cpu and fsize the soft limit is set to the hard limit
936 * if the hard limit is left at its default value and the soft limit
937 * is changed from its default value, either by requesting it
938 * (slim == 0) or by setting it to the current default. At least
939 * that's how rlogind does it. If you're confused you're not alone.
940 * Bug or feature? AIX 4.3.1.2
941 */
942 if ((!strcmp(soft, "fsize") || !strcmp(soft, "cpu"))
943 && hlim == 0 && slim != 0)
944 rlim.rlim_max = rlim.rlim_cur;
945 /* A specified hard limit limits the soft limit */
946 else if (hlim > 0 && rlim.rlim_cur > rlim.rlim_max)
947 rlim.rlim_cur = rlim.rlim_max;
948 /* A soft limit can increase a hard limit */
949 else if (rlim.rlim_cur > rlim.rlim_max)
950 rlim.rlim_max = rlim.rlim_cur;
951
952 if (setrlimit(resource, &rlim) != 0)
953 error("setrlimit(%.10s) failed: %.100s", soft, strerror(errno));
954}
955
956void set_limits_from_userattr(char *user)
957{
958 int mask;
959 char buf[16];
960
961 set_limit(user, S_UFSIZE, S_UFSIZE_HARD, RLIMIT_FSIZE, 512);
962 set_limit(user, S_UCPU, S_UCPU_HARD, RLIMIT_CPU, 1);
963 set_limit(user, S_UDATA, S_UDATA_HARD, RLIMIT_DATA, 512);
964 set_limit(user, S_USTACK, S_USTACK_HARD, RLIMIT_STACK, 512);
965 set_limit(user, S_URSS, S_URSS_HARD, RLIMIT_RSS, 512);
966 set_limit(user, S_UCORE, S_UCORE_HARD, RLIMIT_CORE, 512);
967#if defined(S_UNOFILE)
968 set_limit(user, S_UNOFILE, S_UNOFILE_HARD, RLIMIT_NOFILE, 1);
969#endif
970
971 if (getuserattr(user, S_UMASK, &mask, SEC_INT) != -1) {
972 /* Convert decimal to octal */
973 (void) snprintf(buf, sizeof(buf), "%d", mask);
974 if (sscanf(buf, "%o", &mask) == 1)
975 umask(mask);
976 }
977}
978#endif /* defined(HAVE_GETUSERATTR) */
979
980/* 886/*
981 * Performs common processing for the child, such as setting up the 887 * Performs common processing for the child, such as setting up the
982 * environment, closing extra file descriptors, setting the user and group 888 * environment, closing extra file descriptors, setting the user and group
@@ -1082,22 +988,7 @@ do_child(Session *s, const char *command)
1082 irix_setusercontext(pw); 988 irix_setusercontext(pw);
1083# endif /* defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) */ 989# endif /* defined(WITH_IRIX_PROJECT) || defined(WITH_IRIX_JOBS) || defined(WITH_IRIX_ARRAY) */
1084#ifdef _AIX 990#ifdef _AIX
1085 /* 991 aix_usrinfo(s)
1086 * AIX has a "usrinfo" area where logname and
1087 * other stuff is stored - a few applications
1088 * actually use this and die if it's not set
1089 */
1090 if (s->ttyfd == -1)
1091 s->tty[0] = '\0';
1092 cp = xmalloc(22 + strlen(s->tty) +
1093 2 * strlen(pw->pw_name));
1094 i = sprintf(cp, "LOGNAME=%s%cNAME=%s%cTTY=%s%c%c",
1095 pw->pw_name, 0, pw->pw_name, 0, s->tty, 0, 0);
1096 if (usrinfo(SETUINFO, cp, i) == -1)
1097 fatal("Couldn't set usrinfo: %s",
1098 strerror(errno));
1099 debug3("AIX/UsrInfo: set len %d", i);
1100 xfree(cp);
1101#endif 992#endif
1102 993
1103 /* Permanently switch to the desired uid. */ 994 /* Permanently switch to the desired uid. */