1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
Index: Linux-PAM/doc/modules/pam_limits.sgml
===================================================================
--- Linux-PAM/doc/modules/pam_limits.sgml (revision 274)
+++ Linux-PAM/doc/modules/pam_limits.sgml (working copy)
@@ -155,6 +155,7 @@
<item><tt/priority/ - the priority to run user process with (negative
values boost process priority)
<item><tt/locks/ - max locked files (Linux 2.4 and higher)
+<item><tt/chroot/ - directory to chroot user to
</itemize>
<p>
@@ -197,6 +198,7 @@
@faculty soft nproc 20
@faculty hard nproc 50
ftp hard nproc 0
+ftp - chroot /ftp
@student - maxlogins 4
</verb>
</tscreen>
Index: Linux-PAM/modules/pam_limits/pam_limits.c
===================================================================
--- Linux-PAM/modules/pam_limits/pam_limits.c (revision 274)
+++ Linux-PAM/modules/pam_limits/pam_limits.c (working copy)
@@ -72,6 +72,7 @@
int flag_numsyslogins; /* whether to limit logins only for a
specific user or to count all logins */
int priority; /* the priority to run user process with */
+ char chroot_dir[8092] ; /* directory to chroot into */
int supported[RLIM_NLIMITS];
struct user_limits_struct limits[RLIM_NLIMITS];
char conf_file[BUFSIZ];
@@ -83,6 +84,7 @@
#define LIMIT_NUMSYSLOGINS RLIM_NLIMITS+2
#define LIMIT_PRI RLIM_NLIMITS+3
+#define LIMIT_CHROOT RLIM_NLIMITS+4
#define LIMIT_SOFT 1
#define LIMIT_HARD 2
@@ -251,6 +253,8 @@
pl->login_limit = -2;
pl->login_limit_def = LIMITS_DEF_NONE;
+ pl->chroot_dir[0] = '\0';
+
return retval;
}
@@ -309,6 +313,8 @@
pl->flag_numsyslogins = 1;
} else if (strcmp(lim_item, "priority") == 0) {
limit_item = LIMIT_PRI;
+ } else if (strcmp(lim_item, "chroot") == 0) {
+ limit_item = LIMIT_CHROOT;
} else {
_pam_log(LOG_DEBUG,"unknown limit item '%s'", lim_item);
return;
@@ -368,7 +374,8 @@
if ( (limit_item != LIMIT_LOGIN)
&& (limit_item != LIMIT_NUMSYSLOGINS)
- && (limit_item != LIMIT_PRI) ) {
+ && (limit_item != LIMIT_PRI)
+ && (limit_item != LIMIT_CHROOT)) {
if (limit_type & LIMIT_SOFT) {
if (pl->limits[limit_item].src_soft < source) {
return;
@@ -390,6 +397,8 @@
if (limit_item == LIMIT_PRI) {
pl->priority = limit_value;
+ } else if (limit_item == LIMIT_CHROOT) {
+ strncpy(pl->chroot_dir, value_orig, sizeof(pl->chroot_dir));
} else {
if (pl->login_limit_def < source) {
return;
@@ -567,6 +576,14 @@
retval |= LOGIN_ERR;
}
+
+ if (!retval && pl->chroot_dir[0]) {
+ i = chdir(pl->chroot_dir);
+ if (i == 0)
+ i = chroot(pl->chroot_dir);
+ if (i != 0)
+ retval = LIMIT_ERR;
+ }
return retval;
}
|