exist (Bug 600351 - kukuk)
* pam_mkhomedir: Set owner/permissions of home directory after we
created all files (Bug 1032922 - kukuk)
+* pam_rhosts: Get ride of static buffer for path (kukuk)
0.79: Thu Mar 31 16:48:45 CEST 2005
* pam_tally: added audit option (toady)
FILE *hostf;
uid_t uid;
int answer;
- char pbuf[MAXPATHLEN]; /* potential buffer overrun */
+ char *fpath;
if ((!superuser||opts->opt_hosts_equiv_rootok) && !opts->opt_no_hosts_equiv ) {
return(1);
}
- /* check for buffer overrun */
- if (strlen(pwd->pw_dir) + sizeof(USER_RHOSTS_FILE) + 2 >= MAXPATHLEN) {
- if (opts->opt_debug)
- _pam_log(LOG_DEBUG,"home directory for `%s' is too long", luser);
- return 1; /* to dangerous to try */
+ fpath = malloc (strlen (pwd->pw_dir) + strlen (USER_RHOSTS_FILE) + 1);
+ if (fpath == NULL) {
+ _pam_log (LOG_ALERT, "Running out of memory");
+ return 1;
}
- (void) strcpy(pbuf, pwd->pw_dir);
- (void) strcat(pbuf, USER_RHOSTS_FILE);
+ strcpy (fpath, pwd->pw_dir);
+ strcat (fpath, USER_RHOSTS_FILE);
/*
* Change effective uid while _reading_ .rhosts. (not just
#ifdef __linux__
/* If we are on linux the better way is setfsuid */
uid = setfsuid(pwd->pw_uid);
- hostf = fopen(pbuf, "r");
+ hostf = fopen(fpath, "r");
#else
uid = geteuid();
(void) seteuid(pwd->pw_uid);
- hostf = fopen(pbuf, "r");
+ hostf = fopen(fpath, "r");
#endif
if (hostf == NULL) {
if (opts->opt_debug)
- _pam_log(LOG_DEBUG,"Could not open %s file",pbuf);
+ _pam_log(LOG_DEBUG,"Could not open %s file",fpath);
answer = 1;
goto exit_function;
}
*/
cp = NULL;
- if (lstat(pbuf, &sbuf) < 0 || !S_ISREG(sbuf.st_mode))
+ if (lstat(fpath, &sbuf) < 0 || !S_ISREG(sbuf.st_mode))
cp = ".rhosts not regular file";
else if (fstat(fileno(hostf), &sbuf) < 0)
cp = ".rhosts fstat failed";
(void)seteuid(uid);
#endif
+ free (fpath);
+
if (hostf != NULL)
(void) fclose(hostf);