Changeset 502 in openpam
- Timestamp:
- Dec 18, 2011, 1:59:22 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/openpam_dynamic.c
r494 r502 40 40 #endif 41 41 42 #include <sys/types.h>43 #include <sys/stat.h>44 45 42 #include <dlfcn.h> 46 43 #include <errno.h> 47 #include <libgen.h>48 44 #include <stdio.h> 49 45 #include <stdlib.h> … … 62 58 * OpenPAM internal 63 59 * 64 * Verify that a file or directory is owned by either root or the65 * arbitrator and that it is not writable by group or other.66 */67 68 static int69 check_owner_perms(const char *path)70 {71 struct stat sb;72 73 if (stat(path, &sb) != 0)74 return (-1);75 if ((sb.st_uid != 0 && sb.st_uid != geteuid()) ||76 (sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {77 openpam_log(PAM_LOG_ERROR,78 "%s: insecure ownership or permissions", path);79 errno = EPERM;80 return (-1);81 }82 return (0);83 }84 85 /*86 * OpenPAM internal87 *88 60 * Perform sanity checks and attempt to load a module 89 61 */ … … 92 64 try_dlopen(const char *modfn) 93 65 { 94 char *moddn;95 int ok, serrno;96 66 97 /* 98 * BSD dirname(3) returns a pointer to a static buffer, while GNU 99 * dirname(3) modifies the input string. Use a copy of the string 100 * so both cases work. 101 */ 102 if ((moddn = strdup(modfn)) == NULL) 67 if (openpam_check_path_owner_perms(modfn) != 0) 103 68 return (NULL); 104 ok = (check_owner_perms(dirname(moddn)) == 0 && 105 check_owner_perms(modfn) == 0); 106 serrno = errno; 107 FREE(moddn); 108 errno = serrno; 109 return (ok ? dlopen(modfn, RTLD_NOW) : NULL); 69 return (dlopen(modfn, RTLD_NOW)); 110 70 } 111 71
Note: See TracChangeset
for help on using the changeset viewer.