File: setgroups_none.c

package info (click to toggle)
spiped 1.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,328 kB
  • sloc: ansic: 11,951; sh: 1,081; makefile: 629; perl: 121
file content (62 lines) | stat: -rw-r--r-- 1,445 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * APISUPPORT CFLAGS: NONPOSIX_SETGROUPS
 */

/*
 * There is no setgroups() in the POSIX standard, so if we want to drop
 * supplementary groups, we need to use platform-specific code.  This must
 * happen before the regular includes, as in some cases we need to define other
 * symbols before including the relevant header.
 */
#if defined(__linux__)
/* setgroups() includes for Linux. */
#define _BSD_SOURCE 1
#define _DEFAULT_SOURCE 1

#include <grp.h>

#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
/* setgroups() includes for FreeBSD, NetBSD, MacOS X. */
#include <sys/param.h>
#include <unistd.h>

#elif defined(__OpenBSD__) || defined(__osf__)
/* setgroups() includes for OpenBSD. */
#include <sys/types.h>
#include <unistd.h>

#elif defined(__sun) || defined(__hpux)
/* setgroups() includes for Solaris. */
#include <unistd.h>

#elif defined(_AIX)
/* setgroups() includes for AIX. */
#include <grp.h>

#else
/* Unknown OS; we don't know how to get setgroups(). */
#define NO_SETGROUPS

#endif /* end includes for setgroups() */

#include <stddef.h>

#include "setgroups_none.h"

/**
 * setgroups_none(void):
 * Attempt to leave all supplementary groups.  If we do not know how to do this
 * on the platform, return 0 anyway.
 */
int
setgroups_none(void)
{

#ifdef NO_SETGROUPS
	/* Not supported. */
	return (0);
#else
	/* Attempt to leave all supplementary groups. */
	return (setgroups(0, NULL));
#endif
}