summaryrefslogtreecommitdiff
path: root/openbsd-compat/port-aix.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/port-aix.c')
-rw-r--r--openbsd-compat/port-aix.c122
1 files changed, 122 insertions, 0 deletions
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