Branch data Line data Source code
1 : : /***
2 : : This file is part of PulseAudio.
3 : :
4 : : Copyright 2009 Ted Percival
5 : :
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.
10 : :
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.
15 : :
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 : : ***/
21 : :
22 : : #include <config.h>
23 : :
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>
31 : :
32 : : #include <pulsecore/usergroup.h>
33 : : #include <pulsecore/core-util.h>
34 : :
35 : : static int load_reference_structs(struct group **gr, struct passwd **pw) {
36 : 1 : setpwent();
37 : 1 : *pw = getpwent();
38 : 1 : endpwent();
39 : :
40 : 1 : setgrent();
41 : 1 : *gr = getgrent();
42 : 1 : endgrent();
43 : :
44 [ + - ][ + - ]: 1 : return (*gr && *pw) ? 0 : 1;
45 : : }
46 : :
47 : 2 : static int compare_group(const struct group *a, const struct group *b) {
48 : : char **amem, **bmem;
49 : :
50 [ - + ]: 2 : if (!pa_streq(a->gr_name, b->gr_name)) {
51 : 0 : fprintf(stderr, "Group name mismatch: [%s] [%s]\n", a->gr_name, b->gr_name);
52 : 0 : return 1;
53 : : }
54 : :
55 [ - + ]: 2 : if (!pa_streq(a->gr_passwd, b->gr_passwd)) {
56 : 0 : fprintf(stderr, "Group password mismatch: [%s] [%s]\n", a->gr_passwd, b->gr_passwd);
57 : 0 : return 1;
58 : : }
59 : :
60 [ - + ]: 2 : if (a->gr_gid != b->gr_gid) {
61 : 0 : fprintf(stderr, "Gid mismatch: [%lu] [%lu]\n", (unsigned long) a->gr_gid, (unsigned long) b->gr_gid);
62 : 0 : return 1;
63 : : }
64 : :
65 : : /* XXX: Assuming the group ordering is identical. */
66 [ + + ][ + - ]: 4 : for (amem = a->gr_mem, bmem = b->gr_mem; *amem && *bmem; ++amem, ++bmem) {
67 [ - + ]: 2 : if (!pa_streq(*amem, *bmem)) {
68 : 0 : fprintf(stderr, "Group member mismatch: [%s] [%s]\n", *amem, *bmem);
69 : 0 : return 1;
70 : : }
71 : : }
72 : :
73 [ + - ][ - + ]: 2 : if (*amem || *bmem) {
74 : 0 : fprintf(stderr, "Mismatched group count\n");
75 : 2 : return 1;
76 : : }
77 : :
78 : : return 0;
79 : : }
80 : :
81 : 2 : static int compare_passwd(const struct passwd *a, const struct passwd *b) {
82 [ - + ]: 2 : if (!pa_streq(a->pw_name, b->pw_name)) {
83 : 0 : fprintf(stderr, "pw_name mismatch: [%s] [%s]\n", a->pw_name, b->pw_name);
84 : 0 : return 1;
85 : : }
86 : :
87 [ - + ]: 2 : if (!pa_streq(a->pw_passwd, b->pw_passwd)) {
88 : 0 : fprintf(stderr, "pw_passwd mismatch: [%s] [%s]\n", a->pw_passwd, b->pw_passwd);
89 : 0 : return 1;
90 : : }
91 : :
92 [ - + ]: 2 : if (a->pw_uid != b->pw_uid) {
93 : 0 : fprintf(stderr, "pw_uid mismatch: [%lu] [%lu]\n", (unsigned long) a->pw_uid, (unsigned long) b->pw_uid);
94 : 0 : return 1;
95 : : }
96 : :
97 [ - + ]: 2 : if (a->pw_gid != b->pw_gid) {
98 : 0 : fprintf(stderr, "pw_gid mismatch: [%lu] [%lu]\n", (unsigned long) a->pw_gid, (unsigned long) b->pw_gid);
99 : 0 : return 1;
100 : : }
101 : :
102 [ - + ]: 2 : if (!pa_streq(a->pw_gecos, b->pw_gecos)) {
103 : 0 : fprintf(stderr, "pw_gecos mismatch: [%s] [%s]\n", a->pw_gecos, b->pw_gecos);
104 : 0 : return 1;
105 : : }
106 : :
107 [ - + ]: 2 : if (!pa_streq(a->pw_dir, b->pw_dir)) {
108 : 0 : fprintf(stderr, "pw_dir mismatch: [%s] [%s]\n", a->pw_dir, b->pw_dir);
109 : 0 : return 1;
110 : : }
111 : :
112 [ - + ]: 2 : if (!pa_streq(a->pw_shell, b->pw_shell)) {
113 : 0 : fprintf(stderr, "pw_shell mismatch: [%s] [%s]\n", a->pw_shell, b->pw_shell);
114 : 2 : return 1;
115 : : }
116 : :
117 : : return 0;
118 : : }
119 : :
120 : 1 : int main(int argc, char *argv[]) {
121 : : struct group *gr;
122 : : struct passwd *pw;
123 : : int err;
124 : 1 : struct group *reference_group = NULL;
125 : 1 : struct passwd *reference_passwd = NULL;
126 : :
127 : 1 : err = load_reference_structs(&reference_group, &reference_passwd);
128 [ + - ]: 1 : if (err)
129 : : return 77;
130 : :
131 : 1 : errno = 0;
132 : 1 : gr = pa_getgrgid_malloc(reference_group->gr_gid);
133 [ + - ]: 1 : if (compare_group(reference_group, gr))
134 : : return 1;
135 : 1 : pa_getgrgid_free(gr);
136 : :
137 : 1 : errno = 0;
138 : 1 : gr = pa_getgrnam_malloc(reference_group->gr_name);
139 [ + - ]: 1 : if (compare_group(reference_group, gr))
140 : : return 1;
141 : 1 : pa_getgrnam_free(gr);
142 : :
143 : 1 : errno = 0;
144 : 1 : pw = pa_getpwuid_malloc(reference_passwd->pw_uid);
145 [ + - ]: 1 : if (compare_passwd(reference_passwd, pw))
146 : : return 1;
147 : 1 : pa_getpwuid_free(pw);
148 : :
149 : 1 : errno = 0;
150 : 1 : pw = pa_getpwnam_malloc(reference_passwd->pw_name);
151 [ + - ]: 1 : if (compare_passwd(reference_passwd, pw))
152 : : return 1;
153 : 1 : pa_getpwnam_free(pw);
154 : :
155 : 1 : return 0;
156 : : }
|