]> git.pld-linux.org Git - packages/pam.git/blob - pam-mkhomedir-new-features.patch
- updated to 1.0.0
[packages/pam.git] / pam-mkhomedir-new-features.patch
1 diff -urN Linux-PAM-0.99.7.1.orig/modules/pam_mkhomedir/Makefile.am Linux-PAM-0.99.7.1/modules/pam_mkhomedir/Makefile.am
2 --- Linux-PAM-0.99.7.1.orig/modules/pam_mkhomedir/Makefile.am   2006-06-01 20:53:15.000000000 +0200
3 +++ Linux-PAM-0.99.7.1/modules/pam_mkhomedir/Makefile.am        2007-02-03 22:09:37.950620500 +0100
4 @@ -25,6 +25,10 @@
5  pam_mkhomedir_la_SOURCES = pam_mkhomedir.c
6  pam_mkhomedir_la_LIBADD = -L$(top_builddir)/libpam -lpam
7  
8 +install-exec-local:
9 +       $(LN_S) pam_mkhomedir.so $(DESTDIR)$(SECUREDIR)/pam_homedir.so
10 +       echo ".so pam_mkhomedir.8" > $(DESTDIR)$(man8dir)/pam_homedir.8
11 +
12  if ENABLE_REGENERATE_MAN
13  noinst_DATA = README
14  README: pam_mkhomedir.8.xml
15 diff -urN Linux-PAM-0.99.7.1.orig/modules/pam_mkhomedir/pam_mkhomedir.8.xml Linux-PAM-0.99.7.1/modules/pam_mkhomedir/pam_mkhomedir.8.xml
16 --- Linux-PAM-0.99.7.1.orig/modules/pam_mkhomedir/pam_mkhomedir.8.xml   2006-05-30 15:03:09.000000000 +0200
17 +++ Linux-PAM-0.99.7.1/modules/pam_mkhomedir/pam_mkhomedir.8.xml        2007-02-03 22:09:37.942620000 +0100
18 @@ -29,6 +29,18 @@
19          umask=<replaceable>mode</replaceable>
20        </arg>
21        <arg choice="opt">
22 +        defmode=<replaceable>mode</replaceable>
23 +      </arg>
24 +      <arg choice="opt">
25 +        minmode=<replaceable>mode</replaceable>
26 +      </arg>
27 +      <arg choice="opt">
28 +        chmod
29 +      </arg>
30 +      <arg choice="opt">
31 +        notfound=[<replaceable>create</replaceable>|<replaceable>deny</replaceable>|<replaceable>ignore</replaceable>]
32 +      </arg>
33 +      <arg choice="opt">
34          skel=<replaceable>skeldir</replaceable>
35        </arg>
36      </cmdsynopsis>
37 @@ -82,6 +94,59 @@
38  
39        <varlistentry>
40          <term>
41 +          <option>defmode=<replaceable>mode</replaceable></option>
42 +        </term>
43 +        <listitem>
44 +          <para>
45 +            Default permissions for the home directory.
46 +           The default value of <replaceable>mode</replaceable> is
47 +            0755.
48 +          </para>
49 +        </listitem>
50 +      </varlistentry>
51 +
52 +      <varlistentry>
53 +        <term>
54 +          <option>minmode=<replaceable>mode</replaceable></option>
55 +        </term>
56 +        <listitem>
57 +          <para>
58 +            Minimal permissions for the home directory.
59 +           The default value of <replaceable>mode</replaceable> is
60 +            0755.
61 +          </para>
62 +        </listitem>
63 +      </varlistentry>
64 +
65 +      <varlistentry>
66 +        <term>
67 +          <option>chmod</option>
68 +        </term>
69 +        <listitem>
70 +          <para>
71 +            If this option is specified and home directory access
72 +           permissions has more bits set than in minmode then
73 +           do `chmod defmode $HOME`.
74 +          </para>
75 +        </listitem>
76 +      </varlistentry>
77 +
78 +      <varlistentry>
79 +        <term>
80 +          <option>notfound=[<replaceable>create</replaceable>|<replaceable>deny</replaceable>|<replaceable>ignore</replaceable>]</option>
81 +        </term>
82 +        <listitem>
83 +          <para>
84 +            What to do if home directory is not found or it is not a directory.
85 +           <replaceable>create</replaceable> - default, make home directory;
86 +           <replaceable>deny</replaceable> - deny access;
87 +           <replaceable>ignore</replaceable> - do nothing
88 +          </para>
89 +        </listitem>
90 +      </varlistentry>
91 +
92 +      <varlistentry>
93 +        <term>
94            <option>skel=<replaceable>/path/to/skel/directory</replaceable></option>
95          </term>
96          <listitem>
97 diff -urN Linux-PAM-0.99.7.1.orig/modules/pam_mkhomedir/pam_mkhomedir.c Linux-PAM-0.99.7.1/modules/pam_mkhomedir/pam_mkhomedir.c
98 --- Linux-PAM-0.99.7.1.orig/modules/pam_mkhomedir/pam_mkhomedir.c       2006-12-07 13:34:26.000000000 +0100
99 +++ Linux-PAM-0.99.7.1/modules/pam_mkhomedir/pam_mkhomedir.c    2007-02-03 22:09:37.890616750 +0100
100 @@ -58,17 +58,43 @@
101  
102  
103  /* argument parsing */
104 -#define MKHOMEDIR_DEBUG      020       /* be verbose about things */
105 -#define MKHOMEDIR_QUIET      040       /* keep quiet about things */
106 -
107 -static unsigned int UMask = 0022;
108 -static char SkelDir[BUFSIZ] = "/etc/skel"; /* THIS MODULE IS NOT THREAD SAFE */
109 +#define MKHOMEDIR_DEBUG      0x10      /* keep quiet about things */
110 +#define MKHOMEDIR_QUIET      0x20      /* keep quiet about things */
111 +/* what to do, if home directory does not exist? */
112 +#define HOMEDIR_CREATE       0x40      /* create it */
113 +#define HOMEDIR_BARF         0x80      /* deny access */
114 +
115 +struct homedir_options {
116 +   unsigned int home_access;   /* create ~/ by default */
117 +   unsigned int default_mode;  /* 0755 access rights for home dir */
118 +   unsigned int minimal_mode;  /* 0755 but this is enough... */
119 +   unsigned int umask;         /* 0022 umask for ~/ files */
120 +   unsigned int do_chmod;      /* chmod user ~ if it has insecure permissions */
121 +#ifdef PATH_MAX
122 +   char skel_dir[PATH_MAX];
123 +#else
124 +   char skel_dir[BUFSIZ];
125 +#endif
126 +};
127  
128  static int
129 -_pam_parse (const pam_handle_t *pamh, int flags, int argc, const char **argv)
130 +_pam_parse (const pam_handle_t *pamh, struct homedir_options *opt,
131 +               int flags, int argc, const char **argv)
132  {
133     int ctrl = 0;
134  
135 +   opt->home_access = HOMEDIR_CREATE;
136 +   opt->default_mode = 0755;
137 +   opt->minimal_mode = 0755;
138 +   opt->do_chmod = 0;
139 +#ifdef PATH_MAX
140 +   strncpy(opt->skel_dir, "/etc/skel", PATH_MAX-1);
141 +   opt->skel_dir[PATH_MAX-1] = '\0';
142 +#else
143 +   strncpy(opt->skel_dir, "/etc/skel", BUFSIZ-1);
144 +   opt->skel_dir[BUFSIZ-1] = '\0';
145 +#endif
146 +
147     /* does the appliction require quiet? */
148     if ((flags & PAM_SILENT) == PAM_SILENT)
149        ctrl |= MKHOMEDIR_QUIET;
150 @@ -79,10 +105,35 @@
151        } else if (!strcmp(*argv, "debug")) {
152           ctrl |= MKHOMEDIR_DEBUG;
153        } else if (!strncmp(*argv,"umask=",6)) {
154 -        UMask = strtol(*argv+6,0,0);
155 +        opt->umask = strtol(*argv+6,0,0);
156 +        opt->default_mode = opt->minimal_mode = 0777 & ~(opt->umask);
157 +      } else if (!strncmp(*argv,"defmode=",8))
158 +        opt->default_mode = strtol(*argv+8,0,0);
159 +      else if (!strncmp(*argv,"minmode=",8))
160 +        opt->minimal_mode = strtol(*argv+8,0,0);
161 +      else if (!strncmp(*argv,"chmod",5))
162 +        opt->do_chmod = 1;
163 +      else if (!strncmp(*argv,"notfound=",9))
164 +      {
165 +        if (!strcmp(*argv + 9, "create"))
166 +           opt->home_access = HOMEDIR_CREATE;
167 +        else if (!strcmp(*argv + 9, "deny"))
168 +           opt->home_access = HOMEDIR_BARF;
169 +        else if (!strcmp(*argv + 9, "ignore"))
170 +           opt->home_access &= ~(HOMEDIR_CREATE | HOMEDIR_BARF);
171 +        else
172 +        {
173 +           pam_syslog(pamh, LOG_ERR, "unknown parameter for \"create\" option: %s", *argv + 9);
174 +           opt->home_access = HOMEDIR_CREATE;
175 +        }
176        } else if (!strncmp(*argv,"skel=",5)) {
177 -        strncpy(SkelDir,*argv+5,sizeof(SkelDir));
178 -        SkelDir[sizeof(SkelDir)-1] = '\0';
179 +#ifdef PATH_MAX
180 +             strncpy(opt->skel_dir, *argv+5, PATH_MAX-1);
181 +             opt->skel_dir[PATH_MAX-1] = '\0';
182 +#else
183 +             strncpy(opt->skel_dir, *argv+5, BUFSIZ-1);
184 +             opt->skel_dir[BUFSIZ-1] = '\0';
185 +#endif
186        } else {
187          pam_syslog(pamh, LOG_ERR, "unknown option: %s", *argv);
188        }
189 @@ -127,7 +178,7 @@
190  /* Do the actual work of creating a home dir */
191  static int
192  create_homedir (pam_handle_t * pamh, int ctrl,
193 -               const struct passwd *pwd,
194 +               const struct passwd *pwd, struct homedir_options *opt,
195                 const char *source, const char *dest)
196  {
197     char remark[BUFSIZ];
198 @@ -292,7 +292,7 @@
199        /* If it's a directory, recurse. */
200        if (S_ISDIR(St.st_mode))
201        {
202 -        retval = create_homedir (pamh, ctrl, pwd, newsource, newdest);
203 +        retval = create_homedir (pamh, ctrl, pwd, opt, newsource, newdest);
204  
205  #ifndef PATH_MAX
206          free(newsource); newsource = NULL;
207 @@ -372,10 +423,10 @@
208          return PAM_PERM_DENIED;
209        }
210  
211 -      /* Set the proper ownership and permissions for the module. We make
212 +      /* Set the proper ownership and permissions for the file. We make
213                  the file a+w and then mask it with the set mask. This preseves
214                  execute bits */
215 -      if (fchmod(DestFd,(St.st_mode | 0222) & (~UMask)) != 0 ||
216 +      if (fchmod(DestFd,(St.st_mode | 0222) & (~opt->umask)) != 0 ||
217           fchown(DestFd,pwd->pw_uid,pwd->pw_gid) != 0)
218        {
219           pam_syslog(pamh, LOG_DEBUG,
220 @@ -435,7 +486,7 @@
221  
222   go_out:
223  
224 -   if (chmod(dest,0777 & (~UMask)) != 0 ||
225 +   if (chmod(dest, opt->default_mode) != 0 ||
226         chown(dest,pwd->pw_uid,pwd->pw_gid) != 0)
227     {
228        pam_syslog(pamh, LOG_DEBUG,
229 @@ -446,6 +497,63 @@
230     return retval;
231  }
232  
233 +/* Do the actual work of creating a home dir */
234 +static int check_homedir(pam_handle_t * pamh, int ctrl,
235 +                        const struct passwd *pwd,
236 +                        struct homedir_options *opt)
237 +{
238 +   struct stat stbuf;
239 +   
240 +   /* Stat the home directory, if something exists then we assume it is
241 +      correct and return a success */
242 +   if (stat(pwd->pw_dir, &stbuf) == 0) {
243 +      if (stbuf.st_mode & ~(opt->minimal_mode | S_IFDIR)) {
244 +        /* Aieee, user did something bad to his/hers home */
245 +        if (!S_ISDIR(stbuf.st_mode)) {
246 +           /* This user home is really broken... */
247 +           pam_info(pamh, "Home directory '%s' is not a directory!", pwd->pw_dir);
248 +
249 +           pam_syslog(pamh, LOG_DEBUG, "directory %s is not a directory (mode 0%o)", pwd->pw_dir, stbuf.st_mode);
250 +           if (opt->home_access == HOMEDIR_BARF)
251 +              return PAM_PERM_DENIED;
252 +           else if (opt->home_access == HOMEDIR_CREATE) {
253 +              pam_syslog(pamh, LOG_DEBUG, "trying to unlink directory %s", pwd->pw_dir);
254 +              if (unlink(pwd->pw_dir) == -1) {
255 +                 pam_syslog(pamh, LOG_DEBUG, "failed to unlink directory %s", pwd->pw_dir);
256 +                 return PAM_PERM_DENIED;
257 +              }
258 +           } else
259 +              return PAM_SUCCESS;
260 +        } else {
261 +           pam_info(pamh, "Home directory '%s' has insecure permissions 0%o.",
262 +                       pwd->pw_dir, stbuf.st_mode);
263 +
264 +           pam_syslog(pamh, LOG_DEBUG, "directory %s has insecure permissions 0%o", pwd->pw_dir, stbuf.st_mode);
265 +
266 +           if (opt->do_chmod)
267 +              if (chmod(pwd->pw_dir, opt->default_mode) < 0) {
268 +                 pam_syslog(pamh, LOG_DEBUG, "unable to chmod home directory %s", pwd->pw_dir);
269 +                 return PAM_PERM_DENIED;
270 +              }
271 +           return PAM_SUCCESS;
272 +        }
273 +      } else
274 +           return PAM_SUCCESS;
275 +   }
276 +
277 +   switch (opt->home_access) {
278 +      case HOMEDIR_CREATE:
279 +          return create_homedir(pamh, ctrl, pwd, opt, opt->skel_dir, pwd->pw_dir);
280 +      case HOMEDIR_BARF:
281 +          return PAM_PERM_DENIED;
282 +      default:
283 +          return PAM_SUCCESS;
284 +   }
285 +
286 +   /* If we ever get here sue authors of the compiler */
287 +   return PAM_SERVICE_ERR;
288 +}
289 +
290  /* --- authentication management functions (only) --- */
291  
292  PAM_EXTERN int
293 @@ -456,10 +572,10 @@
294     int retval, ctrl;
295     const void *user;
296     const struct passwd *pwd;
297 -   struct stat St;
298 +   struct homedir_options opt;
299  
300     /* Parse the flag values */
301 -   ctrl = _pam_parse(pamh, flags, argc, argv);
302 +   ctrl = _pam_parse(pamh, &opt, flags, argc, argv);
303  
304     /* Determine the user name so we can get the home directory */
305     retval = pam_get_item(pamh, PAM_USER, &user);
306 @@ -476,12 +593,7 @@
307        return PAM_CRED_INSUFFICIENT;
308     }
309  
310 -   /* Stat the home directory, if something exists then we assume it is
311 -      correct and return a success*/
312 -   if (stat(pwd->pw_dir,&St) == 0)
313 -      return PAM_SUCCESS;
314 -
315 -   return create_homedir(pamh,ctrl,pwd,SkelDir,pwd->pw_dir);
316 +   return check_homedir(pamh, ctrl, pwd, &opt);
317  }
318  
319  /* Ignore */
This page took 0.047972 seconds and 3 git commands to generate.