Use openpam_check_path_owner_perms()

git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@502 185d5e19-27fe-0310-9dcf-9bff6b9f3609
This commit is contained in:
Dag-Erling Smørgrav 2011-12-18 13:59:22 +00:00
parent 996a845863
commit dd498bc7ad
1 changed files with 2 additions and 42 deletions

View File

@ -39,12 +39,8 @@
# include "config.h"
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include <errno.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -58,30 +54,6 @@
#define RTLD_NOW RTLD_LAZY
#endif
/*
* OpenPAM internal
*
* Verify that a file or directory is owned by either root or the
* arbitrator and that it is not writable by group or other.
*/
static int
check_owner_perms(const char *path)
{
struct stat sb;
if (stat(path, &sb) != 0)
return (-1);
if ((sb.st_uid != 0 && sb.st_uid != geteuid()) ||
(sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
openpam_log(PAM_LOG_ERROR,
"%s: insecure ownership or permissions", path);
errno = EPERM;
return (-1);
}
return (0);
}
/*
* OpenPAM internal
*
@ -91,22 +63,10 @@ check_owner_perms(const char *path)
static void *
try_dlopen(const char *modfn)
{
char *moddn;
int ok, serrno;
/*
* BSD dirname(3) returns a pointer to a static buffer, while GNU
* dirname(3) modifies the input string. Use a copy of the string
* so both cases work.
*/
if ((moddn = strdup(modfn)) == NULL)
if (openpam_check_path_owner_perms(modfn) != 0)
return (NULL);
ok = (check_owner_perms(dirname(moddn)) == 0 &&
check_owner_perms(modfn) == 0);
serrno = errno;
FREE(moddn);
errno = serrno;
return (ok ? dlopen(modfn, RTLD_NOW) : NULL);
return (dlopen(modfn, RTLD_NOW));
}
/*