summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-02-19 20:27:55 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-02-19 20:27:55 +0000
commita9c039cf04291cbdb57d4c6200808de9ecb08569 (patch)
treee5d27e6e07944a4567bbcfcc0b193ef6561f5c23 /openbsd-compat
parentf095a8588237010852a3a85f971197a3a5b1d9ae (diff)
- (bal) Migrated AIX getuserattr and usrinfo code to
openbsd-compat/port-aix.[c] to improve readilbity of do_child() and simplify our diffs against upstream source.
Diffstat (limited to 'openbsd-compat')
-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
4 files changed, 136 insertions, 3 deletions
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 */