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 |
78 |
|
svr = strdup(svr); |
79 |
|
|
80 |
|
if (mapping == NULL){ |
80 |
– |
printf("New malloc\n"); |
81 |
|
mapping = malloc(sizeof(mapping_t)); |
82 |
|
if (mapping == NULL) return; |
83 |
|
map_ptr = mapping; |
85 |
|
/* See if its already been added */ |
86 |
|
for(map_ptr = mapping; map_ptr != NULL; map_ptr = map_ptr->next){ |
87 |
|
if( (!strcmp(map_ptr->bsd, bsd)) || (!strcmp(map_ptr->svr, svr)) ){ |
88 |
– |
printf("%s matches %s\n", map_ptr->bsd, bsd); |
88 |
|
return; |
89 |
|
} |
90 |
|
map_end_ptr = map_ptr; |
94 |
|
* new mapping_t |
95 |
|
*/ |
96 |
|
map_end_ptr->next = malloc(sizeof(mapping_t)); |
98 |
– |
printf("Second malloc\n"); |
97 |
|
if (map_end_ptr->next == NULL) return; |
98 |
|
map_ptr = map_end_ptr->next; |
99 |
|
} |
100 |
|
|
103 |
– |
printf("Adding %s\n", bsd); |
101 |
|
map_ptr->next = NULL; |
102 |
|
map_ptr->bsd = bsd; |
103 |
|
map_ptr->svr = svr; |
107 |
|
|
108 |
|
char *read_dir(char *disk_path){ |
109 |
|
DIR *dirp; |
110 |
< |
struct dirent *dp; |
111 |
< |
struct stat stbuf; |
110 |
> |
struct dirent *dp; |
111 |
> |
struct stat stbuf; |
112 |
|
char *svr_name; |
113 |
< |
char current_dir[MAXPATHLEN]; |
114 |
< |
char file_name[MAXPATHLEN]; |
115 |
< |
char temp_name[MAXPATHLEN]; |
116 |
< |
char dir_dname[MAXPATHLEN]; |
113 |
> |
char current_dir[MAXPATHLEN]; |
114 |
> |
char file_name[MAXPATHLEN]; |
115 |
> |
char temp_name[MAXPATHLEN]; |
116 |
> |
char dir_dname[MAXPATHLEN]; |
117 |
|
char *dsk_dir; |
118 |
|
int x; |
119 |
|
|
120 |
|
dsk_dir = "/dev/osa/dev/dsk"; |
121 |
< |
strncpy(current_dir, dsk_dir, sizeof current_dir); |
122 |
< |
if ((dirp = opendir(current_dir)) == NULL){ |
121 |
> |
strncpy(current_dir, dsk_dir, sizeof current_dir); |
122 |
> |
if ((dirp = opendir(current_dir)) == NULL){ |
123 |
|
dsk_dir = "/dev/dsk"; |
124 |
|
snprintf(current_dir, sizeof current_dir, "%s", dsk_dir); |
125 |
|
if ((dirp = opendir(current_dir)) == NULL){ |
127 |
|
} |
128 |
|
} |
129 |
|
|
130 |
< |
while ((dp = readdir(dirp)) != NULL){ |
130 |
> |
while ((dp = readdir(dirp)) != NULL){ |
131 |
|
snprintf(temp_name, sizeof temp_name, "../..%s", disk_path); |
132 |
|
snprintf(dir_dname, sizeof dir_dname, "%s/%s", dsk_dir, dp->d_name); |
133 |
|
stat(dir_dname,&stbuf); |
141 |
|
return svr_name; |
142 |
|
} |
143 |
|
} |
147 |
– |
closedir(dirp); |
144 |
|
} |
145 |
+ |
closedir(dirp); |
146 |
|
return NULL; |
147 |
|
} |
148 |
|
|
159 |
|
char *value; |
160 |
|
int instance; |
161 |
|
if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) { |
162 |
< |
fprintf(stderr, "di_init() failed\n"); |
166 |
< |
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); |
182 |
|
}else{ |
183 |
|
node = di_drv_next_node(node); |
184 |
|
} |
185 |
< |
} /* End of the while loop */ |
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; |
194 |
< |
kstat_t *ksp; |
195 |
< |
kstat_io_t kios; |
193 |
> |
kstat_ctl_t *kc; |
194 |
> |
kstat_t *ksp; |
195 |
> |
kstat_io_t kios; |
196 |
|
|
197 |
|
if ((kc = kstat_open()) == NULL) { |
198 |
< |
return NULL; |
199 |
< |
} |
198 |
> |
return; |
199 |
> |
} |
200 |
|
|
201 |
< |
for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) { |
202 |
< |
if (!strcmp(ksp->ks_class, "disk")) { |
203 |
< |
|
204 |
< |
if(ksp->ks_type != KSTAT_TYPE_IO) continue; |
205 |
< |
/* We dont want metadevices appearins as num_diskio */ |
206 |
< |
if(strcmp(ksp->ks_module, "md")==0) continue; |
211 |
< |
if((kstat_read(kc, ksp, &kios))==-1) continue; |
201 |
> |
for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) { |
202 |
> |
if (!strcmp(ksp->ks_class, "disk")) { |
203 |
> |
if(ksp->ks_type != KSTAT_TYPE_IO) continue; |
204 |
> |
/* We dont want metadevices appearing as num_diskio */ |
205 |
> |
if(strcmp(ksp->ks_module, "md")==0) continue; |
206 |
> |
if((kstat_read(kc, ksp, &kios))==-1) continue; |
207 |
|
strncpy(device_name, ksp->ks_name, sizeof device_name); |
208 |
|
for(x=0;x<(sizeof device_name);x++){ |
209 |
|
if( isdigit((int)device_name[x]) ) break; |
210 |
|
} |
211 |
|
if(x == sizeof device_name) x--; |
212 |
|
device_name[x] = '\0'; |
213 |
< |
get_alias(device_name); |
214 |
< |
} |
213 |
> |
if((get_alias(device_name)) != 0){ |
214 |
> |
return 1; |
215 |
> |
} |
216 |
> |
} |
217 |
|
} |
218 |
< |
|
219 |
< |
return; |
218 |
> |
|
219 |
> |
return 0; |
220 |
|
} |
221 |
|
|
222 |
|
#endif |
324 |
|
#ifdef ALLBSD |
325 |
|
{ |
326 |
|
kvm_t *kvmd = get_kvm(); |
327 |
< |
if (kvmd == NULL) return 1; |
327 |
> |
if (kvmd == NULL) return 1; |
328 |
|
} |
329 |
|
#endif |
330 |
|
#ifdef NETBSD |
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 |
+ |
|