View | Details | Raw Unified | Return to bug 261 | Differences between
and this patch

Collapse All | Expand All

(-)openbsd-compat/port-aix.c (-69 / +6 lines)
Lines 24-102 Link Here
24
/*
24
/*
25
 * AIX-specific login initialisation
25
 * AIX-specific login initialisation
26
 */
26
 */
27
void 
28
set_limit(char *user, char *soft, char *hard, int resource, int mult)
29
{
30
        struct rlimit rlim;
31
        int slim, hlim;
32
33
        getrlimit(resource, &rlim);
34
35
        slim = 0;
36
        if (getuserattr(user, soft, &slim, SEC_INT) != -1) {
37
                if (slim < 0) {
38
                        rlim.rlim_cur = RLIM_INFINITY;
39
                } else if (slim != 0) {
40
                        /* See the wackiness below */
41
                        if (rlim.rlim_cur == slim * mult)
42
                                slim = 0;
43
                        else
44
                                rlim.rlim_cur = slim * mult;
45
                }
46
        }
47
        hlim = 0;
48
        if (getuserattr(user, hard, &hlim, SEC_INT) != -1) {
49
                if (hlim < 0) {
50
                        rlim.rlim_max = RLIM_INFINITY;
51
                } else if (hlim != 0) {
52
                        rlim.rlim_max = hlim * mult;
53
                }
54
        }
55
56
        /*
57
         * XXX For cpu and fsize the soft limit is set to the hard limit
58
         * if the hard limit is left at its default value and the soft limit
59
         * is changed from its default value, either by requesting it
60
         * (slim == 0) or by setting it to the current default.  At least
61
         * that's how rlogind does it.  If you're confused you're not alone.
62
         * Bug or feature? AIX 4.3.1.2
63
         */
64
        if ((!strcmp(soft, "fsize") || !strcmp(soft, "cpu"))
65
            && hlim == 0 && slim != 0)
66
                rlim.rlim_max = rlim.rlim_cur;
67
        /* A specified hard limit limits the soft limit */
68
        else if (hlim > 0 && rlim.rlim_cur > rlim.rlim_max)
69
                rlim.rlim_cur = rlim.rlim_max;
70
        /* A soft limit can increase a hard limit */
71
        else if (rlim.rlim_cur > rlim.rlim_max)
72
                rlim.rlim_max = rlim.rlim_cur;
73
74
        if (setrlimit(resource, &rlim) != 0)
75
                error("setrlimit(%.10s) failed: %.100s", soft, strerror(errno));
76
}
77
27
78
void 
28
void 
79
set_limits_from_userattr(char *user)
29
set_limits_from_userattr(char *user)
80
{
30
{
81
        int mask;
31
	/* 
82
        char buf[16];
32
	   Set up the process credentials and process environment
83
33
	   based on the AIX userdatabase. 
84
        set_limit(user, S_UFSIZE, S_UFSIZE_HARD, RLIMIT_FSIZE, 512);
34
	*/
85
        set_limit(user, S_UCPU, S_UCPU_HARD, RLIMIT_CPU, 1);
35
	setpcred (user, NULL);
86
        set_limit(user, S_UDATA, S_UDATA_HARD, RLIMIT_DATA, 512);
36
	setpenv (user, PENV_INIT, NULL, NULL); 
87
        set_limit(user, S_USTACK, S_USTACK_HARD, RLIMIT_STACK, 512);
88
        set_limit(user, S_URSS, S_URSS_HARD, RLIMIT_RSS, 512);
89
        set_limit(user, S_UCORE, S_UCORE_HARD, RLIMIT_CORE, 512);
90
#if defined(S_UNOFILE)
91
        set_limit(user, S_UNOFILE, S_UNOFILE_HARD, RLIMIT_NOFILE, 1);
92
#endif
93
94
        if (getuserattr(user, S_UMASK, &mask, SEC_INT) != -1) {
95
                /* Convert decimal to octal */
96
                (void) snprintf(buf, sizeof(buf), "%d", mask);
97
                if (sscanf(buf, "%o", &mask) == 1)
98
                        umask(mask);
99
        }
100
}
37
}
101
#endif /* defined(HAVE_GETUSERATTR) */
38
#endif /* defined(HAVE_GETUSERATTR) */
102
39
(-)openbsd-compat/port-aix.h (-1 lines)
Lines 1-7 Link Here
1
#ifdef _AIX
1
#ifdef _AIX
2
2
3
#ifdef HAVE_GETUSERATTR
3
#ifdef HAVE_GETUSERATTR
4
void set_limit(char *user, char *soft, char *hard, int resource, int mult);
5
void set_limits_from_userattr(char *user);
4
void set_limits_from_userattr(char *user);
6
#endif /* HAVE_GETUSERATTR */
5
#endif /* HAVE_GETUSERATTR */
7
6

Return to bug 261