1
--- Linux-PAM-0.72.orig/modules/pam_mkhomedir/pam_mkhomedir.c Mon Nov 8 06:45:36 1999
2
+++ Linux-PAM-0.72/modules/pam_mkhomedir/pam_mkhomedir.c Wed Feb 7 15:24:27 2001
7
-/* Do the actual work of creating a home dir */
8
-static int create_homedir(pam_handle_t * pamh, int ctrl,
9
- const struct passwd *pwd)
10
+int copy_skel(char *SkelDir, char *SubPath, const struct passwd *pwd)
17
/* Some scratch space */
18
remark = malloc(BUFSIZ);
21
- D(("no memory for last login remark"));
25
- /* Mention what is happening, if the notification fails that is OK */
26
- if (snprintf(remark,BUFSIZ,"Creating home directory '%s'.",
28
- return PAM_PERM_DENIED;
30
- make_remark(pamh, ctrl, remark);
32
- /* Crete the home directory */
33
- if (mkdir(pwd->pw_dir,0700) != 0)
36
- _log_err(LOG_DEBUG, "unable to create home directory %s",pwd->pw_dir);
37
- return PAM_PERM_DENIED;
39
- if (chmod(pwd->pw_dir,0777 & (~UMask)) != 0 ||
40
- chown(pwd->pw_dir,pwd->pw_uid,pwd->pw_gid) != 0)
43
- _log_err(LOG_DEBUG, "unable to chance perms on home directory %s",pwd->pw_dir);
44
- return PAM_PERM_DENIED;
46
+ snprintf(remark,BUFSIZ,"%s%s",SkelDir,SubPath);
48
- /* See if we need to copy the skel dir over. */
49
- if (SkelDir[0] == 0)
55
/* Scan the directory */
56
- D = opendir(SkelDir);
57
+ D = opendir(remark);
60
+ _log_err(LOG_DEBUG, "unable to read directory %s",remark);
62
- _log_err(LOG_DEBUG, "unable to read directory %s",SkelDir);
63
return PAM_PERM_DENIED;
69
/* Check if it is a directory */
70
- snprintf(remark,BUFSIZ,"%s/%s",SkelDir,Dir->d_name);
71
+ snprintf(remark,BUFSIZ,"%s%s/%s",SkelDir,SubPath,Dir->d_name);
72
if (stat(remark,&St) != 0)
74
if (S_ISDIR(St.st_mode))
76
- snprintf(remark,BUFSIZ,"%s/%s",pwd->pw_dir,Dir->d_name);
77
+ snprintf(remark,BUFSIZ,"%s%s/%s",pwd->pw_dir,SubPath,Dir->d_name);
78
if (mkdir(remark,(St.st_mode | 0222) & (~UMask)) != 0 ||
79
chmod(remark,(St.st_mode | 0222) & (~UMask)) != 0 ||
80
chown(remark,pwd->pw_uid,pwd->pw_gid) != 0)
83
_log_err(LOG_DEBUG, "unable to change perms on copy %s",remark);
85
return PAM_PERM_DENIED;
87
+ snprintf(remark,BUFSIZ,"%s/%s",SubPath,Dir->d_name);
88
+ ret=copy_skel(SkelDir,remark,pwd);
89
+ if (ret!=PAM_SUCCESS) {
96
/* Open the source file */
97
if ((SrcFd = open(remark,O_RDONLY)) < 0 || fstat(SrcFd,&St) != 0)
100
_log_err(LOG_DEBUG, "unable to open src file %s",remark);
102
return PAM_PERM_DENIED;
106
/* Open the dest file */
107
- snprintf(remark,BUFSIZ,"%s/%s",pwd->pw_dir,Dir->d_name);
108
+ snprintf(remark,BUFSIZ,"%s%s/%s",pwd->pw_dir,SubPath,Dir->d_name);
109
if ((DestFd = open(remark,O_WRONLY | O_TRUNC | O_CREAT,0600)) < 0)
113
_log_err(LOG_DEBUG, "unable to open dest file %s",remark);
115
return PAM_PERM_DENIED;
119
if (fchmod(DestFd,(St.st_mode | 0222) & (~UMask)) != 0 ||
120
fchown(DestFd,pwd->pw_uid,pwd->pw_gid) != 0)
123
_log_err(LOG_DEBUG, "unable to chang perms on copy %s",remark);
125
return PAM_PERM_DENIED;
137
+/* Do the actual work of creating a home dir */
138
+static int create_homedir(pam_handle_t * pamh, int ctrl,
139
+ const struct passwd *pwd)
143
+ /* Some scratch space */
144
+ remark = malloc(BUFSIZ);
145
+ if (remark == NULL)
147
+ D(("no memory for last login remark"));
148
+ return PAM_BUF_ERR;
151
+ /* Mention what is happening, if the notification fails that is OK */
152
+ if (snprintf(remark,BUFSIZ,"Creating home directory '%s'.",
153
+ pwd->pw_dir) == -1)
154
+ return PAM_PERM_DENIED;
156
+ make_remark(pamh, ctrl, remark);
158
+ /* Crete the home directory */
159
+ if (mkdir(pwd->pw_dir,0700) != 0)
162
+ _log_err(LOG_DEBUG, "unable to create home directory %s",pwd->pw_dir);
163
+ return PAM_PERM_DENIED;
165
+ if (chmod(pwd->pw_dir,0777 & (~UMask)) != 0 ||
166
+ chown(pwd->pw_dir,pwd->pw_uid,pwd->pw_gid) != 0)
169
+ _log_err(LOG_DEBUG, "unable to chance perms on home directory %s",pwd->pw_dir);
170
+ return PAM_PERM_DENIED;
173
+ /* See if we need to copy the skel dir over. */
174
+ if (SkelDir[0] == 0)
177
+ return PAM_SUCCESS;
181
+ return copy_skel(SkelDir,"",pwd);
184
/* --- authentication management functions (only) --- */