Bug Summary

File:obj-scan-build/utils/../../utils/frobauth.c
Location:line 236, column 31
Description:Value stored to 'fs' during its initialization is never read

Annotated Source Code

1/* Common interface for auth frobbing utilities
2
3 Copyright (C) 1997 Free Software Foundation, Inc.
4
5 Written by Miles Bader <miles@gnu.ai.mit.edu>
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21/* This file is rather a mess of intertwined argps; it shoud be redone as a
22 single level once argp can handle dynamic option frobbing. XXX */
23
24#include <stdlib.h>
25#include <unistd.h>
26#include <string.h>
27#include <hurd.h>
28#include <hurd/process.h>
29
30#include "frobauth.h"
31#include "ugids.h"
32#include "pids.h"
33
34static struct argp common_argp;
35static struct argp fr_ugids_argp;
36
37static const struct argp_option common_options[] =
38{
39 {"verbose", 'v', 0, 0, "Print informational messages"},
40 {"dry-run", 'n', 0, 0, "Don't do anything, just print what would be done"},
41 { 0 }
42};
43static struct argp_child common_child_argps[] =
44{
45 { &pids_argp, 0, "Process selection:" },
46 { 0 }
47};
48
49static const char common_args_doc[] = "USER...";
50static const char common_doc[] =
51 "\vBy default, all processes in the current login collection are selected";
52
53static struct argp_child ugids_child_argps[] =
54{
55 { &ugids_argp, 0, "User/group ids:" },
56 { 0 }
57};
58
59/* An argp on top of the base frobauth argp that provides switchable
60 effective/available ids (XXX this junk should be moved into a single argp
61 [indeed, into ugids_argp] once argp can deal with the init routine
62 frobbing the argp source). */
63static const struct argp_option ea_options[] =
64{
65 {"available", 'a', 0, 0, "USER... specifies available ids"},
66 {"effective", 'e', 0, 0, "USER... specifies effective ids"},
67 { 0 }
68};
69
70static struct argp_child ea_posix_child_argps[] =
71{
72 { &common_argp },
73 { &fr_ugids_argp },
74 { 0 }
75};
76
77static struct argp_child no_ugids_child_argps[] =
78{
79 { &common_argp },
80 { 0 }
81};
82
83/* This holds state information that's only active during parsing. */
84struct frobauth_argp_state
85{
86 struct frobauth *frobauth;
87 struct pids_argp_params pids_argp_params;
88 struct ugids_argp_params ugids_argp_params;
89};
90
91static error_t
92common_parse_opt (int key, char *arg, struct argp_state *state)
93{
94 struct frobauth_argp_state *fs = state->input;
95 struct frobauth *frobauth = fs->frobauth;
96
97 switch (key)
98 {
99 case 'v':
100 frobauth->verbose = 1; break;
101 case 'n':
102 frobauth->dry_run = 1; break;
103
104 case ARGP_KEY_END0x1000001:
105 if (frobauth->num_pids == 0)
106 /* No pids specified! By default, do the current login collection. */
107 {
108 pid_t lid;
109 error_t err = proc_getloginid (getproc (), getpid (), &lid);
110
111 if (err)
112 argp_failure (state, 2, err,
113 "Couldn't get current login collection");
114
115 err = add_fn_pids (&frobauth->pids, &frobauth->num_pids,
116 lid, proc_getloginpids);
117 if (err)
118 argp_failure (state, 3, err,
119 "%d: Couldn't get login collection pids", lid);
120
121 return err;
122 }
123 break;
124
125 case ARGP_KEY_INIT0x1000003:
126 bzero (fs, sizeof *fs);
127 fs->frobauth = frobauth;
128 fs->pids_argp_params.pids = &frobauth->pids;
129 fs->pids_argp_params.num_pids = &frobauth->num_pids;
130 state->child_inputs[0] = &fs->pids_argp_params;
131 break;
132
133 case ARGP_KEY_SUCCESS0x1000004:
134 case ARGP_KEY_ERROR0x1000005:
135 free (fs);
136
137 default:
138 return ARGP_ERR_UNKNOWN((0x10 << 26) | ((7) & 0x3fff));
139 }
140 return 0;
141}
142
143static error_t
144ugids_parse_opt (int key, char *arg, struct argp_state *state)
145{
146 struct frobauth_argp_state *fs = state->input;
147 struct frobauth *frobauth = fs->frobauth;
148
149 switch (key)
150 {
151 case ARGP_KEY_INIT0x1000003:
152 fs->ugids_argp_params.ugids = &frobauth->ugids;
153 fs->ugids_argp_params.parse_user_args = 1;
154 fs->ugids_argp_params.default_user = frobauth->default_user;
155 fs->ugids_argp_params.require_ids = frobauth->require_ids;
156 fs->pids_argp_params.pids = &frobauth->pids;
157 fs->pids_argp_params.num_pids = &frobauth->num_pids;
158
159 state->child_inputs[0] = &fs->ugids_argp_params;
160
161 break;
162
163 default:
164 return ARGP_ERR_UNKNOWN((0x10 << 26) | ((7) & 0x3fff));
165 }
166 return 0;
167}
168
169static error_t
170ea_parse_opt (int key, char *arg, struct argp_state *state)
171{
172 struct frobauth_argp_state *fs = state->hook;
173
174 switch (key)
175 {
176 case 'a':
177 fs->ugids_argp_params.user_args_are_available = 1;
178 break;
179 case 'e':
180 fs->ugids_argp_params.user_args_are_effective = 1;
181 break;
182
183 case ARGP_KEY_ARG0:
184 if (!fs->ugids_argp_params.user_args_are_effective
185 && !fs->ugids_argp_params.user_args_are_available)
186 /* Default to effective. */
187 fs->ugids_argp_params.user_args_are_effective = 1;
188
189 /* Let someone else parse the arg. */
190 return ARGP_ERR_UNKNOWN((0x10 << 26) | ((7) & 0x3fff));
191
192 case ARGP_KEY_INIT0x1000003:
193 /* Initialize inputs for child parsers. */
194 fs = state->hook = malloc (sizeof (struct frobauth_argp_state));
195 if (! fs)
196 return ENOMEM((0x10 << 26) | ((12) & 0x3fff));
197
198 fs->frobauth = state->input;
199 state->child_inputs[0] = fs; /* Pass our state to the common parser. */
200 state->child_inputs[1] = fs; /* Pass our state to the common parser. */
201 break;
202
203 default:
204 return ARGP_ERR_UNKNOWN((0x10 << 26) | ((7) & 0x3fff));
205 }
206 return 0;
207}
208
209static error_t
210posix_parse_opt (int key, char *arg, struct argp_state *state)
211{
212 struct frobauth_argp_state *fs = state->hook;
213
214 switch (key)
215 {
216 case ARGP_KEY_INIT0x1000003:
217 /* Initialize inputs for child parsers. */
218 fs = state->hook = malloc (sizeof (struct frobauth_argp_state));
219 if (! fs)
220 return ENOMEM((0x10 << 26) | ((12) & 0x3fff));
221
222 fs->frobauth = state->input;
223 state->child_inputs[0] = fs; /* Pass our state to the common parser. */
224 state->child_inputs[1] = fs; /* Pass our state to the common parser. */
225 break;
226
227 default:
228 return ARGP_ERR_UNKNOWN((0x10 << 26) | ((7) & 0x3fff));
229 }
230 return 0;
231}
232
233static error_t
234no_ugids_parse_opt (int key, char *arg, struct argp_state *state)
235{
236 struct frobauth_argp_state *fs = state->hook;
Value stored to 'fs' during its initialization is never read
237
238 switch (key)
239 {
240 case ARGP_KEY_INIT0x1000003:
241 /* Initialize inputs for child parsers. */
242 fs = state->hook = malloc (sizeof (struct frobauth_argp_state));
243 if (! fs)
244 return ENOMEM((0x10 << 26) | ((12) & 0x3fff));
245
246 fs->frobauth = state->input;
247 state->child_inputs[0] = fs; /* Pass our state to the common parser. */
248 break;
249
250 default:
251 return ARGP_ERR_UNKNOWN((0x10 << 26) | ((7) & 0x3fff));
252 }
253 return 0;
254}
255
256static struct argp common_argp =
257{
258 common_options, common_parse_opt, 0, common_doc, common_child_argps
259};
260static struct argp fr_ugids_argp =
261{
262 0, ugids_parse_opt, 0, 0, ugids_child_argps
263};
264
265/* Parse frobauth args/options, where user args are added as single ids to
266 either the effective or available ids. */
267struct argp frobauth_ea_argp =
268{
269 ea_options, ea_parse_opt, 0, 0, ea_posix_child_argps
270};
271
272/* Parse frobauth args/options, where user args are added as posix user. */
273struct argp frobauth_posix_argp =
274{
275 0, posix_parse_opt, 0, 0, ea_posix_child_argps
276};
277
278/* Parse frobauth args/options, where user args are added as posix user. */
279struct argp frobauth_no_ugids_argp =
280{
281 0, no_ugids_parse_opt, 0, 0, no_ugids_child_argps
282};