64 |
|
#include <sys/fcntl.h> |
65 |
|
#include <dirent.h> |
66 |
|
#endif |
67 |
+ |
#ifdef WIN32 |
68 |
+ |
#include "win32.h" |
69 |
+ |
#endif |
70 |
|
|
71 |
|
#if defined(SOLARIS) && defined(HAVE_LIBDEVINFO_H) |
72 |
|
struct map{ |
179 |
|
di_node_t root_node; |
180 |
|
di_node_t node; |
181 |
|
di_minor_t minor = DI_MINOR_NIL; |
182 |
< |
char tmpnode[MAXPATHLEN]; |
182 |
> |
char tmpnode[MAXPATHLEN + 1]; |
183 |
|
char *phys_path; |
184 |
|
char *minor_name; |
185 |
|
char *value; |
193 |
|
instance = di_instance(node); |
194 |
|
phys_path = di_devfs_path(node); |
195 |
|
minor_name = di_minor_name(minor); |
196 |
< |
strcpy(tmpnode, alias); |
196 |
> |
sg_strlcpy(tmpnode, alias, MAXPATHLEN); |
197 |
|
sprintf(tmpnode, "%s%d", tmpnode, instance); |
198 |
|
sg_strlcpy(file, "/devices", sizeof file); |
199 |
|
sg_strlcat(file, phys_path, sizeof file); |
237 |
|
if(strcmp(ksp->ks_module, "md")==0) continue; |
238 |
|
if((kstat_read(kc, ksp, &kios))==-1) continue; |
239 |
|
strncpy(device_name, ksp->ks_name, sizeof device_name); |
240 |
< |
for(x=0;x<(sizeof device_name);x++){ |
240 |
> |
for(x=0;x<(int)(sizeof device_name);x++){ |
241 |
|
if( isdigit((int)device_name[x]) ) break; |
242 |
|
} |
243 |
|
if(x == sizeof device_name) x--; |
249 |
|
if (x>=BIG_ENOUGH){ |
250 |
|
/* We've got bigger than we thought was massive */ |
251 |
|
/* If we hit this.. Make big enough bigger */ |
252 |
+ |
kstat_close(kc); |
253 |
|
return -1; |
254 |
|
} |
255 |
|
if( !strncmp(driver_list[x], device_name, BIG_ENOUGH)){ |
260 |
|
|
261 |
|
if(!found){ |
262 |
|
if((get_alias(device_name)) != 0){ |
263 |
+ |
kstat_close(kc); |
264 |
|
return -1; |
265 |
|
} |
266 |
|
strncpy(driver_list[x], device_name, BIG_ENOUGH); |
269 |
|
} |
270 |
|
} |
271 |
|
|
272 |
+ |
kstat_close(kc); |
273 |
+ |
|
274 |
|
return 0; |
275 |
|
} |
276 |
|
|
301 |
|
return match_string; |
302 |
|
} |
303 |
|
|
304 |
< |
/* FIXME do Linux and Cygwin always have atoll? */ |
304 |
> |
/* Cygwin (without a recent newlib) doesn't have atoll */ |
305 |
|
#ifndef HAVE_ATOLL |
306 |
|
static long long atoll(const char *s) { |
307 |
|
long long value = 0; |
333 |
|
} |
334 |
|
#endif |
335 |
|
|
336 |
< |
/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */ |
336 |
> |
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ |
337 |
|
|
338 |
|
/* |
339 |
|
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
357 |
|
* Returns strlen(src); if retval >= siz, truncation occurred. |
358 |
|
*/ |
359 |
|
size_t sg_strlcpy(char *dst, const char *src, size_t siz){ |
360 |
< |
register char *d = dst; |
361 |
< |
register const char *s = src; |
362 |
< |
register size_t n = siz; |
360 |
> |
char *d = dst; |
361 |
> |
const char *s = src; |
362 |
> |
size_t n = siz; |
363 |
|
|
364 |
|
/* Copy as many bytes as will fit */ |
365 |
< |
if (n != 0 && --n != 0) { |
366 |
< |
do { |
367 |
< |
if ((*d++ = *s++) == 0) |
365 |
> |
if (n != 0) { |
366 |
> |
while (--n != 0) { |
367 |
> |
if ((*d++ = *s++) == '\0') |
368 |
|
break; |
369 |
< |
} while (--n != 0); |
369 |
> |
} |
370 |
|
} |
371 |
|
|
372 |
|
/* Not enough room in dst, add NUL and traverse rest of src */ |
380 |
|
return(s - src - 1); /* count does not include NUL */ |
381 |
|
} |
382 |
|
|
383 |
< |
/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ */ |
383 |
> |
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ |
384 |
|
|
385 |
|
/* |
386 |
|
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
406 |
|
* If retval >= siz, truncation occurred. |
407 |
|
*/ |
408 |
|
size_t sg_strlcat(char *dst, const char *src, size_t siz){ |
409 |
< |
register char *d = dst; |
410 |
< |
register const char *s = src; |
411 |
< |
register size_t n = siz; |
409 |
> |
char *d = dst; |
410 |
> |
const char *s = src; |
411 |
> |
size_t n = siz; |
412 |
|
size_t dlen; |
413 |
|
|
414 |
|
/* Find the end of dst and adjust bytes left but don't go past end */ |
446 |
|
return -1; |
447 |
|
} |
448 |
|
|
449 |
< |
strcpy(new, src); |
449 |
> |
sg_strlcpy(new, src, strlen(src) + 1); |
450 |
|
*dest = new; |
451 |
|
return 0; |
452 |
|
} |
453 |
|
|
454 |
+ |
/* join two strings together */ |
455 |
+ |
int sg_concat_string(char **dest, const char *src) { |
456 |
+ |
char *new; |
457 |
+ |
int len = strlen(*dest) + strlen(src) + 1; |
458 |
+ |
|
459 |
+ |
new = sg_realloc(*dest, len); |
460 |
+ |
if (new == NULL) { |
461 |
+ |
return -1; |
462 |
+ |
} |
463 |
+ |
|
464 |
+ |
*dest = new; |
465 |
+ |
sg_strlcat(*dest, src, len); |
466 |
+ |
return 0; |
467 |
+ |
} |
468 |
+ |
|
469 |
|
#if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD) |
470 |
|
kvm_t *sg_get_kvm() { |
471 |
|
static kvm_t *kvmd = NULL; |
553 |
|
build_mapping(); |
554 |
|
#endif |
555 |
|
#endif |
556 |
+ |
#ifdef WIN32 |
557 |
+ |
return sg_win32_start_capture(); |
558 |
+ |
#endif |
559 |
|
return 0; |
560 |
|
} |
561 |
|
|
562 |
+ |
int sg_shutdown() { |
563 |
+ |
#ifdef WIN32 |
564 |
+ |
sg_win32_end_capture(); |
565 |
+ |
#endif |
566 |
+ |
return 0; |
567 |
+ |
} |
568 |
+ |
|
569 |
+ |
int sg_snapshot() { |
570 |
+ |
#ifdef WIN32 |
571 |
+ |
return sg_win32_snapshot(); |
572 |
+ |
#else |
573 |
+ |
return 0; |
574 |
+ |
#endif |
575 |
+ |
} |
576 |
+ |
|
577 |
|
int sg_drop_privileges() { |
578 |
+ |
#ifndef WIN32 |
579 |
|
#ifdef HAVE_SETEGID |
580 |
|
if (setegid(getgid()) != 0) { |
581 |
|
#elif defined(HAVE_SETRESGID) |
596 |
|
sg_set_error_with_errno(SG_ERROR_SETEUID, NULL); |
597 |
|
return -1; |
598 |
|
} |
599 |
+ |
#endif /* WIN32 */ |
600 |
|
return 0; |
601 |
|
} |
602 |
|
|