man: Document the local-server-type daemon.conf option.
[pulseaudio-raopUDP/pulseaudio-raop-alac.git] / src / tests / usergroup-test.c
blob3948e0f82aa37862dc5b9c35cf581067e133108c
1 /***
2 This file is part of PulseAudio.
4 Copyright 2009 Ted Percival
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
22 #include <config.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <sys/types.h>
28 #include <pwd.h>
29 #include <grp.h>
30 #include <errno.h>
32 #include <pulsecore/usergroup.h>
34 static int load_reference_structs(struct group **gr, struct passwd **pw) {
35 setpwent();
36 *pw = getpwent();
37 endpwent();
39 setgrent();
40 *gr = getgrent();
41 endgrent();
43 return (*gr && *pw) ? 0 : 1;
46 static int compare_group(const struct group *a, const struct group *b) {
47 char **amem, **bmem;
49 if (strcmp(a->gr_name, b->gr_name)) {
50 fprintf(stderr, "Group name mismatch: [%s] [%s]\n", a->gr_name, b->gr_name);
51 return 1;
54 if (strcmp(a->gr_passwd, b->gr_passwd)) {
55 fprintf(stderr, "Group password mismatch: [%s] [%s]\n", a->gr_passwd, b->gr_passwd);
56 return 1;
59 if (a->gr_gid != b->gr_gid) {
60 fprintf(stderr, "Gid mismatch: [%lu] [%lu]\n", (unsigned long) a->gr_gid, (unsigned long) b->gr_gid);
61 return 1;
64 /* XXX: Assuming the group ordering is identical. */
65 for (amem = a->gr_mem, bmem = b->gr_mem; *amem && *bmem; ++amem, ++bmem) {
66 if (strcmp(*amem, *bmem)) {
67 fprintf(stderr, "Group member mismatch: [%s] [%s]\n", *amem, *bmem);
68 return 1;
72 if (*amem || *bmem) {
73 fprintf(stderr, "Mismatched group count\n");
74 return 1;
77 return 0;
80 static int compare_passwd(const struct passwd *a, const struct passwd *b) {
81 if (strcmp(a->pw_name, b->pw_name)) {
82 fprintf(stderr, "pw_name mismatch: [%s] [%s]\n", a->pw_name, b->pw_name);
83 return 1;
86 if (strcmp(a->pw_passwd, b->pw_passwd)) {
87 fprintf(stderr, "pw_passwd mismatch: [%s] [%s]\n", a->pw_passwd, b->pw_passwd);
88 return 1;
91 if (a->pw_uid != b->pw_uid) {
92 fprintf(stderr, "pw_uid mismatch: [%lu] [%lu]\n", (unsigned long) a->pw_uid, (unsigned long) b->pw_uid);
93 return 1;
96 if (a->pw_gid != b->pw_gid) {
97 fprintf(stderr, "pw_gid mismatch: [%lu] [%lu]\n", (unsigned long) a->pw_gid, (unsigned long) b->pw_gid);
98 return 1;
101 if (strcmp(a->pw_gecos, b->pw_gecos)) {
102 fprintf(stderr, "pw_gecos mismatch: [%s] [%s]\n", a->pw_gecos, b->pw_gecos);
103 return 1;
106 if (strcmp(a->pw_dir, b->pw_dir)) {
107 fprintf(stderr, "pw_dir mismatch: [%s] [%s]\n", a->pw_dir, b->pw_dir);
108 return 1;
111 if (strcmp(a->pw_shell, b->pw_shell)) {
112 fprintf(stderr, "pw_shell mismatch: [%s] [%s]\n", a->pw_shell, b->pw_shell);
113 return 1;
116 return 0;
119 int main(int argc, char *argv[]) {
120 struct group *gr;
121 struct passwd *pw;
122 int err;
123 struct group *reference_group = NULL;
124 struct passwd *reference_passwd = NULL;
126 err = load_reference_structs(&reference_group, &reference_passwd);
127 if (err)
128 return 77;
130 errno = 0;
131 gr = pa_getgrgid_malloc(reference_group->gr_gid);
132 if (compare_group(reference_group, gr))
133 return 1;
134 pa_getgrgid_free(gr);
136 errno = 0;
137 gr = pa_getgrnam_malloc(reference_group->gr_name);
138 if (compare_group(reference_group, gr))
139 return 1;
140 pa_getgrnam_free(gr);
142 errno = 0;
143 pw = pa_getpwuid_malloc(reference_passwd->pw_uid);
144 if (compare_passwd(reference_passwd, pw))
145 return 1;
146 pa_getpwuid_free(pw);
148 errno = 0;
149 pw = pa_getpwnam_malloc(reference_passwd->pw_name);
150 if (compare_passwd(reference_passwd, pw))
151 return 1;
152 pa_getpwnam_free(pw);
154 return 0;