1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | #include <stdlib.h> |
22 | #include <string.h> |
23 | #include <hurd.h> |
24 | #include <ctype.h> |
25 | #include <unistd.h> |
26 | #include <argp.h> |
27 | #include <pwd.h> |
28 | #include <grp.h> |
29 | |
30 | #include <hurd/paths.h> |
31 | #include <hurd/password.h> |
32 | |
33 | #include "ugids.h" |
34 |
|
35 | |
36 | struct svma_state |
37 | { |
38 | |
39 | file_t server; |
40 | |
41 | |
42 | auth_t *auths; |
43 | size_t num_auths; |
44 | }; |
45 | |
46 | |
47 | |
48 | static error_t |
49 | svma_state_add_auths (struct svma_state *ss, |
50 | const auth_t *auths, size_t num_auths) |
51 | { |
52 | auth_t *new = realloc (ss->auths, |
| |
53 | (ss->num_auths + num_auths) * sizeof (auth_t)); |
54 | if (new) |
| 9 | | Assuming 'new' is non-null | |
|
| |
55 | { |
56 | ss->auths = new; |
57 | while (num_auths--) |
| 11 | | Loop condition is true. Entering loop body | |
|
| 12 | | Loop condition is false. Execution continues on line 59 | |
|
58 | ss->auths[ss->num_auths++] = *auths++; |
59 | return 0; |
60 | } |
61 | else |
62 | return ENOMEM((0x10 << 26) | ((12) & 0x3fff)); |
63 | } |
64 | |
65 | |
66 | static error_t |
67 | server_verify_make_auth (const char *password, |
68 | uid_t id, int is_group, |
69 | void *pwd_or_grp, void *hook) |
70 | { |
71 | auth_t auth; |
72 | struct svma_state *svma_state = hook; |
73 | error_t (*check) (io_t server, uid_t id, const char *passwd, auth_t *auth) = |
74 | is_group ? password_check_group : password_check_user; |
75 | error_t err = (*check) (svma_state->server, id, password, &auth); |
76 | |
77 | if (! err) |
78 | |
79 | { |
80 | err = svma_state_add_auths (svma_state, &auth, 1); |
81 | if (err) |
82 | mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), auth); |
83 | } |
84 | |
85 | return err; |
86 | } |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | |
96 | error_t |
97 | ugids_verify_make_auth (const struct ugids *ugids, |
98 | const struct idvec *have_uids, |
99 | const struct idvec *have_gids, |
100 | char *(*getpass_fn) (const char *prompt, |
101 | uid_t id, int is_group, |
102 | void *pwd_or_grp, void *hook), |
103 | void *getpass_hook, |
104 | const auth_t *from, size_t num_from, |
105 | auth_t *auth) |
106 | { |
107 | error_t err; |
108 | |
109 | struct svma_state svma_state; |
110 | error_t (*verify_fn) (const char *password, |
111 | uid_t id, int is_group, |
112 | void *pwd_or_grp, void *hook) |
113 | = server_verify_make_auth; |
114 | void *verify_hook = &svma_state; |
115 | |
116 | |
117 | svma_state.server = file_name_lookup (_SERVERS_PASSWORD"/servers/" "password", 0, 0); |
118 | |
119 | if (svma_state.server == MACH_PORT_NULL((mach_port_t) 0)) |
| |
120 | |
121 | |
122 | { |
123 | verify_fn = 0; |
124 | verify_hook = 0; |
125 | } |
126 | else |
127 | { |
128 | |
129 | svma_state.auths = NULL((void*)0); |
130 | svma_state.num_auths = 0; |
131 | } |
132 | |
133 | |
134 | err = ugids_verify (ugids, have_uids, have_gids, |
135 | getpass_fn, getpass_hook, verify_fn, verify_hook); |
136 | |
137 | if (! err) |
| |
| |
138 | { |
139 | |
140 | |
141 | if (verify_fn) |
| |
142 | |
143 | |
144 | { |
145 | if (num_from > 0) |
| 5 | | Assuming 'num_from' is > 0 | |
|
| |
146 | |
147 | err = svma_state_add_auths (&svma_state, from, num_from); |
| 7 | | Calling 'svma_state_add_auths' | |
|
| 13 | | Returned allocated memory | |
|
148 | |
149 | if (! err) |
| |
150 | { |
151 | auth_t cur_auth = getauth (); |
152 | |
153 | err = |
154 | auth_makeauth (cur_auth, |
155 | svma_state.auths, MACH_MSG_TYPE_COPY_SEND19, |
156 | svma_state.num_auths, |
157 | ugids->eff_uids.ids, ugids->eff_uids.num, |
158 | ugids->avail_uids.ids, ugids->avail_uids.num, |
159 | ugids->eff_gids.ids, ugids->eff_gids.num, |
160 | ugids->avail_gids.ids, ugids->avail_gids.num, |
161 | auth); |
162 | mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), cur_auth); |
163 | |
164 | |
165 | svma_state.num_auths -= num_from; |
166 | } |
167 | } |
168 | else |
169 | |
170 | err = ugids_make_auth (ugids, from, num_from, auth); |
171 | } |
172 | |
173 | if (verify_fn) |
| |
174 | |
175 | { |
176 | unsigned int i; |
177 | |
178 | |
179 | for (i = 0; i < svma_state.num_auths; i++) |
| 16 | | Loop condition is false. Execution continues on line 183 | |
|
180 | mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), svma_state.auths[i]); |
181 | |
182 | |
183 | mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), svma_state.server); |
184 | |
185 | if (svma_state.num_auths > 0) |
| |
186 | free (svma_state.auths); |
187 | } |
188 | |
189 | return err; |
| 18 | | Memory is never released; potential leak of memory pointed to by 'svma_state.auths' |
|
190 | } |