Bug Summary

File:obj-scan-build/utils/../../utils/frobauth-mod.c
Location:line 101, column 4
Description:Value stored to 'err' is never read

Annotated Source Code

1/* Modify the current authentication selected processes
2
3 Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
4 Written by Miles Bader <miles@gnu.ai.mit.edu>
5 This file is part of the GNU Hurd.
6
7 The GNU Hurd 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 The GNU Hurd 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
20
21#include <stdlib.h>
22#include <stdio.h>
23#include <unistd.h>
24#include <string.h>
25#include <hurd.h>
26#include <error.h>
27
28#include "frobauth.h"
29
30/* For every pid in FROBAUTH, call MODIFY to change its argument UGIDS from
31 the current authentication to what it should be; CHANGE is whatever ids
32 the user specified. AUTHS, of length NUM_AUTHS, should be a vector of
33 auth ports giving whatever additional authentication is needed (besides
34 the process's current authentication). If the user specifies the
35 --verbose flags, PRINT_INFO is called after successfully installing the
36 new authentication in each process, to print a message about what
37 happened. True is returned if no errors occur, although most errors do
38 not cause termination, and error messages are printed for them. */
39error_t
40frobauth_modify (struct frobauth *frobauth,
41 const auth_t *auths, size_t num_auths,
42 error_t (*modify) (struct ugids *ugids,
43 const struct ugids *change,
44 pid_t pid, void *hook),
45 void (*print_info) (const struct ugids *new,
46 const struct ugids *old,
47 const struct ugids *change,
48 pid_t pid, void *hook),
49 void *hook)
50{
51 int i;
52 int ok = 1;
53 size_t num_all_auths = num_auths + 1;
54 auth_t all_auths[num_all_auths];
55 pid_t cur_pid = getpid ();
56 process_t proc_server = getproc ();
57
58 bcopy (auths, all_auths, num_auths * sizeof *auths);
59
60 /* Map MODIFY over all pids. */
61 for (i = 0; i < frobauth->num_pids; i++)
62 if (frobauth->pids[i] != cur_pid)
63 {
64 mach_port_t msgport;
65 pid_t pid = frobauth->pids[i];
66 error_t err = proc_getmsgport (proc_server, pid, &msgport);
67
68 if (err)
69 error (0, err, "%d: Cannot get message port", pid);
70 else
71 {
72 task_t task;
73
74 err = proc_pid2task (proc_server, pid, &task);
75 if (err)
76 error (0, err, "%d", pid);
77 else
78 {
79 auth_t old_auth;
80
81 err = msg_get_init_port (msgport, task, INIT_PORT_AUTH,
82 &old_auth);
83 if (err)
84 error (0, err, "%d: Cannot get auth port", pid);
85 else
86 {
87 struct ugids old = UGIDS_INIT{ { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 } };
88
89 err = ugids_merge_auth (&old, old_auth);
90
91 if (err)
92 error (0, err, "%d: Cannot get auth port ids", pid);
93 else
94 {
95 struct ugids new = UGIDS_INIT{ { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 } };
96
97 /* Assume all gids that can be implied by some uid are
98 only present for that reason. */
99 ugids_imply_all (&old);
100
101 err = ugids_set (&new, &old);
Value stored to 'err' is never read
102
103 err = (*modify) (&new, &frobauth->ugids, pid, hook);
104 if (err)
105 error (99, err, "%d: Cannot modify ids", pid);
106 else if (! ugids_equal (&new, &old))
107 {
108 if (! frobauth->dry_run)
109 {
110 auth_t new_auth;
111
112 /* Add the PID's old authentication to that
113 supplied by the calller. */
114 all_auths[num_all_auths - 1] = old_auth;
115
116 err = ugids_make_auth (&new,
117 all_auths,
118 num_all_auths,
119 &new_auth);
120 if (err)
121 error (0, err,
122 "%d: Authentication failure", pid);
123 else
124 {
125 err =
126 msg_set_init_port (msgport, task,
127 INIT_PORT_AUTH,
128 new_auth,
129 MACH_MSG_TYPE_COPY_SEND19);
130 mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)),
131 new_auth);
132 if (err)
133 error (0, err, "%d", pid);
134 }
135
136 }
137
138 if (frobauth->verbose && !err)
139 (*print_info) (&new, &old, &frobauth->ugids,
140 pid, hook);
141
142 }
143 else if (frobauth->verbose)
144 printf ("%d: Nothing changed\n", pid);
145
146 ugids_fini (&new);
147 }
148
149 ugids_fini (&old);
150 mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), old_auth);
151 }
152 mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), task);
153 }
154 mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), msgport);
155 }
156
157 if (err)
158 ok = 0; /* Something didn't work. */
159 }
160
161 return ok;
162}