Debian Codegraph @

debian/patches/008_modules_pam_limits_chroot

raw
1 From: Sam Hartman <[email protected]>
2 Date: Mon, 11 Sep 2023 14:00:42 -0600
3 Subject: _modules_pam_limits_chroot
4
5 ===================================================================
6 ---
7 modules/pam_limits/limits.conf | 2 ++
8 modules/pam_limits/limits.conf.5.xml | 6 ++++++
9 modules/pam_limits/pam_limits.c | 26 ++++++++++++++++++++++----
10 3 files changed, 30 insertions(+), 4 deletions(-)
11
12 diff --git a/modules/pam_limits/limits.conf b/modules/pam_limits/limits.conf
13 index c6b058a..6b3865c 100644
14 --- a/modules/pam_limits/limits.conf
15 +++ b/modules/pam_limits/limits.conf
16 @@ -49,6 +49,7 @@
17 # - msgqueue - max memory used by POSIX message queues (bytes)
18 # - nice - max nice priority allowed to raise to values: [-20, 19]
19 # - rtprio - max realtime priority
20 +# - chroot - change root to directory (Debian-specific)
21 #
22 #<domain> <type> <item> <value>
23 #
24 @@ -60,6 +61,7 @@
25 #@faculty soft nproc 20
26 #@faculty hard nproc 50
27 #ftp hard nproc 0
28 +#ftp - chroot /ftp
29 #@student - maxlogins 4
30
31 # End of file
32 diff --git a/modules/pam_limits/limits.conf.5.xml b/modules/pam_limits/limits.conf.5.xml
33 index 803cb4e..348758a 100644
34 --- a/modules/pam_limits/limits.conf.5.xml
35 +++ b/modules/pam_limits/limits.conf.5.xml
36 @@ -271,6 +271,12 @@
37 (Linux 2.6.12 and higher)</para>
38 </listitem>
39 </varlistentry>
40 + <varlistentry>
41 + <term><option>chroot</option></term>
42 + <listitem>
43 + <para>the directory to chroot the user to</para>
44 + </listitem>
45 + </varlistentry>
46 </variablelist>
47 </listitem>
48 </varlistentry>
49 diff --git a/modules/pam_limits/pam_limits.c b/modules/pam_limits/pam_limits.c
50 index 9f11927..f7487ba 100644
51 --- a/modules/pam_limits/pam_limits.c
52 +++ b/modules/pam_limits/pam_limits.c
53 @@ -108,6 +108,7 @@ struct pam_limit_s {
54 specific user or to count all logins */
55 int priority; /* the priority to run user process with */
56 int nonewprivs; /* whether to prctl(PR_SET_NO_NEW_PRIVS) */
57 + char chroot_dir[8092]; /* directory to chroot into */
58 struct user_limits_struct limits[RLIM_NLIMITS];
59 const char *conf_file;
60 int utmp_after_pam_call;
61 @@ -116,9 +117,9 @@ struct pam_limit_s {
62
63 #define LIMIT_LOGIN (RLIM_NLIMITS+1)
64 #define LIMIT_NUMSYSLOGINS (RLIM_NLIMITS+2)
65 -
66 #define LIMIT_PRI (RLIM_NLIMITS+3)
67 #define LIMIT_NONEWPRIVS (RLIM_NLIMITS+4)
68 +#define LIMIT_CHROOT (RLIM_NLIMITS+5)
69
70 #define LIMIT_SOFT 1
71 #define LIMIT_HARD 2
72 @@ -653,6 +654,8 @@ static int init_limits(pam_handle_t *pamh, struct pam_limit_s *pl, int ctrl)
73 pl->login_limit_def = LIMITS_DEF_NONE;
74 pl->login_group = NULL;
75
76 + pl->chroot_dir[0] = '\0';
77 +
78 return retval;
79 }
80
81 @@ -763,6 +766,8 @@ process_limit (const pam_handle_t *pamh, int source, const char *lim_type,
82 limit_item = LIMIT_PRI;
83 } else if (strcmp(lim_item, "nonewprivs") == 0) {
84 limit_item = LIMIT_NONEWPRIVS;
85 + } else if (strcmp(lim_item, "chroot") == 0) {
86 + limit_item = LIMIT_CHROOT;
87 } else {
88 pam_syslog(pamh, LOG_DEBUG, "unknown limit item '%s'", lim_item);
89 return;
90 @@ -812,9 +817,9 @@ process_limit (const pam_handle_t *pamh, int source, const char *lim_type,
91 pam_syslog(pamh, LOG_DEBUG,
92 "wrong limit value '%s' for limit type '%s'",
93 lim_value, lim_type);
94 - return;
95 + return;
96 }
97 - } else {
98 + } else if (limit_item != LIMIT_CHROOT) {
99 #ifdef __USE_FILE_OFFSET64
100 rlimit_value = strtoull (lim_value, &endptr, 10);
101 #else
102 @@ -889,7 +894,11 @@ process_limit (const pam_handle_t *pamh, int source, const char *lim_type,
103 break;
104 }
105
106 - if ( (limit_item != LIMIT_LOGIN)
107 + if (limit_item == LIMIT_CHROOT) {
108 + strncpy(pl->chroot_dir, value_orig, sizeof(pl->chroot_dir)-1);
109 + pl->chroot_dir[sizeof(pl->chroot_dir)-1]='\0';
110 + }
111 + else if ( (limit_item != LIMIT_LOGIN)
112 && (limit_item != LIMIT_NUMSYSLOGINS)
113 && (limit_item != LIMIT_PRI)
114 && (limit_item != LIMIT_NONEWPRIVS) ) {
115 @@ -1307,6 +1316,15 @@ static int setup_limits(pam_handle_t *pamh,
116 #endif
117 }
118
119 + if (!retval && pl->chroot_dir[0]) {
120 + i = chdir(pl->chroot_dir);
121 + if (i == 0)
122 + i = chroot(pl->chroot_dir);
123 + if (i == 0)
124 + i = chdir("/");
125 + if (i != 0)
126 + retval = LIMIT_ERR;
127 + }
128 return retval;
129 }
130