25 |
|
#include <stdio.h> |
26 |
|
#include <string.h> |
27 |
|
#include <stdlib.h> |
28 |
+ |
#include <unistd.h> |
29 |
|
#include <sys/types.h> |
30 |
|
#include <regex.h> |
31 |
|
#ifdef ALLBSD |
159 |
|
char *value; |
160 |
|
int instance; |
161 |
|
if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) { |
162 |
< |
fprintf(stderr, "di_init() failed\n"); |
162 |
< |
exit(1); |
162 |
> |
return 1; |
163 |
|
} |
164 |
|
node = di_drv_first_node(alias, root_node); |
165 |
|
while (node != DI_NODE_NIL) { |
169 |
|
minor_name = di_minor_name(minor); |
170 |
|
strcpy(tmpnode, alias); |
171 |
|
sprintf(tmpnode, "%s%d", tmpnode, instance); |
172 |
< |
strcpy(file, "/devices"); |
173 |
< |
strcat(file, phys_path); |
174 |
< |
strcat(file, ":"); |
175 |
< |
strcat(file, minor_name); |
172 |
> |
strlcpy(file, "/devices", sizeof file); |
173 |
> |
strlcat(file, phys_path, sizeof file); |
174 |
> |
strlcat(file, ":", sizeof file); |
175 |
> |
strlcat(file, minor_name, sizeof file); |
176 |
|
value = read_dir(file); |
177 |
|
if (value != NULL){ |
178 |
|
add_mapping(tmpnode, value); |
184 |
|
} |
185 |
|
} |
186 |
|
di_fini(root_node); |
187 |
< |
return (-1); |
187 |
> |
return 0; |
188 |
|
} |
189 |
|
|
190 |
< |
void build_mapping(){ |
190 |
> |
int build_mapping(){ |
191 |
|
char device_name[512]; |
192 |
|
int x; |
193 |
|
kstat_ctl_t *kc; |
210 |
|
} |
211 |
|
if(x == sizeof device_name) x--; |
212 |
|
device_name[x] = '\0'; |
213 |
< |
get_alias(device_name); |
213 |
> |
if((get_alias(device_name)) != 0){ |
214 |
> |
return 1; |
215 |
> |
} |
216 |
|
} |
217 |
|
} |
218 |
|
|
219 |
< |
return; |
219 |
> |
return 0; |
220 |
|
} |
221 |
|
|
222 |
|
#endif |
334 |
|
} |
335 |
|
#endif |
336 |
|
#ifdef SOLARIS |
337 |
< |
build_mapping(); |
337 |
> |
if((build_mapping()) != 0) return 1; |
338 |
|
#endif |
339 |
|
return 0; |
340 |
|
} |
341 |
+ |
|
342 |
+ |
int statgrab_drop_privileges() { |
343 |
+ |
if (setegid(getgid()) != 0) return -1; |
344 |
+ |
if (seteuid(getuid()) != 0) return -1; |
345 |
+ |
return 0; |
346 |
+ |
} |
347 |
+ |
|