|
Lines 65-71
Link Here
|
| 65 |
#include <syslog.h> |
65 |
#include <syslog.h> |
| 66 |
#include <string.h> |
66 |
#include <string.h> |
| 67 |
#include <errno.h> |
67 |
#include <errno.h> |
| 68 |
#include <dirent.h> |
68 |
#include <glob.h> |
| 69 |
#include <paths.h> |
69 |
#include <paths.h> |
| 70 |
#include <unistd.h> |
70 |
#include <unistd.h> |
| 71 |
#include "pathnames.h" |
71 |
#include "pathnames.h" |
|
Lines 121-160
Link Here
|
| 121 |
/* login_protect - protect one device entry */ |
121 |
/* login_protect - protect one device entry */ |
| 122 |
|
122 |
|
| 123 |
void |
123 |
void |
| 124 |
login_protect(table, path, mask, uid, gid) |
124 |
login_protect(table, pattern, mask, uid, gid) |
| 125 |
char *table; |
125 |
char *table; |
| 126 |
char *path; |
126 |
char *pattern; |
| 127 |
int mask; |
127 |
int mask; |
| 128 |
uid_t uid; |
128 |
uid_t uid; |
| 129 |
gid_t gid; |
129 |
gid_t gid; |
| 130 |
{ |
130 |
{ |
| 131 |
char buf[BUFSIZ]; |
131 |
glob_t gl; |
| 132 |
int pathlen = strlen(path); |
132 |
char *path; |
| 133 |
struct dirent *ent; |
133 |
int i; |
| 134 |
DIR *dir; |
134 |
|
| 135 |
|
135 |
if (glob(pattern, GLOB_NOSORT, NULL, &gl) != 0) |
| 136 |
if (strcmp("/*", path + pathlen - 2) != 0) { |
136 |
return; |
| 137 |
/* clear flags of the device */ |
137 |
for (i = 0; i < gl.gl_pathc; i++) { |
| 138 |
if (chflags(path, 0) && errno != ENOENT && errno != EOPNOTSUPP) |
138 |
path = gl.gl_pathv[i]; |
| 139 |
syslog(LOG_ERR, "%s: chflags(%s): %m", table, path); |
139 |
/* clear flags of the device */ |
| 140 |
if (chmod(path, mask) && errno != ENOENT) |
140 |
if (chflags(path, 0) && errno != ENOENT && errno != EOPNOTSUPP) |
| 141 |
syslog(LOG_ERR, "%s: chmod(%s): %m", table, path); |
141 |
syslog(LOG_ERR, "%s: chflags(%s): %m", table, path); |
| 142 |
if (chown(path, uid, gid) && errno != ENOENT) |
142 |
if (chmod(path, mask) && errno != ENOENT) |
| 143 |
syslog(LOG_ERR, "%s: chown(%s): %m", table, path); |
143 |
syslog(LOG_ERR, "%s: chmod(%s): %m", table, path); |
| 144 |
} else { |
144 |
if (chown(path, uid, gid) && errno != ENOENT) |
| 145 |
strcpy(buf, path); |
145 |
syslog(LOG_ERR, "%s: chown(%s): %m", table, path); |
| 146 |
buf[pathlen - 1] = 0; |
|
|
| 147 |
if ((dir = opendir(buf)) == 0) { |
| 148 |
syslog(LOG_ERR, "%s: opendir(%s): %m", table, path); |
| 149 |
} else { |
| 150 |
while ((ent = readdir(dir)) != 0) { |
| 151 |
if (strcmp(ent->d_name, ".") != 0 |
| 152 |
&& strcmp(ent->d_name, "..") != 0) { |
| 153 |
strcpy(buf + pathlen - 1, ent->d_name); |
| 154 |
login_protect(table, buf, mask, uid, gid); |
| 155 |
} |
| 156 |
} |
| 157 |
closedir(dir); |
| 158 |
} |
146 |
} |
| 159 |
} |
147 |
globfree(&gl); |
| 160 |
} |
148 |
} |