about summary refs log tree commit diff
path: root/src/passwd/getgr_a.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/passwd/getgr_a.c')
-rw-r--r--src/passwd/getgr_a.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/passwd/getgr_a.c b/src/passwd/getgr_a.c
new file mode 100644
index 00000000..805e28c9
--- /dev/null
+++ b/src/passwd/getgr_a.c
@@ -0,0 +1,32 @@
+#include <pthread.h>
+#include "pwf.h"
+
+int __getgr_a(const char *name, gid_t gid, struct group *gr, char **buf, size_t *size, char ***mem, size_t *nmem, struct group **res)
+{
+	FILE *f;
+	int rv = 0;
+	int cs;
+
+	*res = 0;
+
+	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
+
+	f = fopen("/etc/group", "rbe");
+	if (!f) {
+		rv = errno;
+		goto done;
+	}
+
+	while (!(rv = __getgrent_a(f, gr, buf, size, mem, nmem, res)) && *res) {
+		if (name && !strcmp(name, (*res)->gr_name)
+		|| !name && (*res)->gr_gid == gid) {
+			break;
+		}
+	}
+	fclose(f);
+
+done:
+	pthread_setcancelstate(cs, 0);
+	if (rv) errno = rv;
+	return rv;
+}