Bug Summary

File:kauth/user.c
Location:line 174, column 5
Description:Value stored to 'old' is never read

Annotated Source Code

1/*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10/* This file provides the easiest, turn-key interface to the authication
11 * package. */
12
13#include <afsconfig.h>
14#include <afs/param.h>
15#include <afs/stds.h>
16
17#include <roken.h>
18
19#include <hcrypto/des.h>
20#include <hcrypto/ui.h>
21
22#include <afs/com_err.h>
23#include <afs/cellconfig.h>
24#include <afs/auth.h>
25#include <afs/ptint.h>
26#include <afs/pterror.h>
27#include <afs/ptuser.h>
28#include <afs/ptserver.h>
29#include <afs/afsutil.h>
30
31#ifndef UKERNEL1
32#include <afs/sys_prototypes.h>
33#endif
34
35#include <rx/rx.h>
36#include <rx/rx_globals.h>
37#include <rx/rxkad.h> /* max ticket lifetime */
38
39
40#include "kauth.h"
41#include "kautils.h"
42#include <afs/ktc.h>
43
44afs_int32
45GetTickets(char *name, char *instance, char *realm,
46 struct ktc_encryptionKey * key, Dateafs_uint32 lifetime,
47 afs_int32 * pwexpires, afs_int32 flags)
48{
49 afs_int32 code;
50
51 code = ka_GetAuthToken(name, instance, realm, key, lifetime, pwexpires);
52 memset(key, 0, sizeof(*key));
53 if (code)
54 return code;
55 code = ka_GetAFSTicket(name, instance, realm, lifetime, flags);
56 return code;
57}
58
59/*
60 * Requires that you already possess a TGT.
61 */
62afs_int32
63ka_GetAFSTicket(char *name, char *instance, char *realm, Dateafs_uint32 lifetime,
64 afs_int32 flags)
65{
66 afs_int32 code;
67 struct ktc_token token;
68 struct ktc_principal server, client;
69
70 code = ka_GetServerToken("afs", "", realm, lifetime, &token, /*new */ 1,
71 /*dosetpag */ flags);
72 if (code)
73 return code;
74 if (ktc_OldPioctl()) {
75 int local;
76 char username[MAXKTCNAMELEN64];
77 afs_int32 viceId;
78 int len;
79 char *whoami = "UserAuthenticate: ptserver";
80
81 strcpy(server.name, "afs");
82 strcpy(server.instance, "");
83 code = ka_ExpandCell(realm, server.cell, &local);
84 if (code)
85 return code;
86 code = pr_Initialize(0, AFSDIR_CLIENT_ETC_DIRPATHgetDirPath(AFSDIR_CLIENT_ETC_DIRPATH_ID), server.cell);
87 if (code) {
88 afs_com_err(whoami, code, "initializing ptserver in cell '%s'",
89 server.cell);
90 return 0;
91 }
92 len = strlen(name);
93 if (instance[0])
94 len += strlen(instance) + 1;
95 if (len >= sizeof(username)) {
96 fprintf(stderr__stderrp, "user's name '%s'.'%s' would be too large\n",
97 name, instance);
98 return 0;
99 }
100 strcpy(username, name);
101 if (instance[0]) {
102 strcat(username, ".");
103 strcat(username, instance);
104 }
105 code = pr_SNameToId(username, &viceId);
106 /* Before going further, shutdown the pr ubik connection */
107 pr_End();
108 if ((code == 0) && (viceId == ANONYMOUSID32766))
109 code = PRNOENT(267268L);
110 if (code) {
111 afs_com_err(whoami, code, "translating %s to id", username);
112 return 0;
113 }
114
115 sprintf(client.name, "AFS ID %d", viceId);
116 strcpy(client.instance, "");
117 strcpy(client.cell, server.cell);
118 code = ktc_SetToken(&server, &token, &client, /*dosetpag */ 0);
119 if (code)
120 return code;
121 }
122 return code;
123}
124
125#ifdef ka_UserAuthenticate
126#undef ka_UserAuthenticate
127#endif
128
129afs_int32
130ka_UserAuthenticateGeneral(afs_int32 flags, char *name, char *instance,
131 char *realm, char *password, Dateafs_uint32 lifetime,
132 afs_int32 * password_expires, /* days 'til, or don't change if not set */
133 afs_int32 spare2, char **reasonP)
134{
135 int remainingTime = 0;
136 struct ktc_encryptionKey key;
137 afs_int32 code, dosetpag = 0;
138#if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_USR_LINUX20_ENV) && !defined(AFS_XBSD_ENV) || defined(AFS_FBSD_ENV)
139 void (*old)(int);
140#endif
141
142 if (reasonP)
143 *reasonP = "";
144 if ((flags & KA_USERAUTH_VERSION_MASK0x00ffff) != KA_USERAUTH_VERSION1)
145 return KAOLDINTERFACE(180491L);
146 if ((strcmp(name, "root") == 0) && (instance == 0)) {
147 if (reasonP)
148 *reasonP = "root is only authenticated locally";
149 return KANOENT(180484L);
150 }
151 code = ka_Init(0);
152 if (code)
153 return code;
154
155 ka_StringToKey(password, realm, &key);
156
157/*
158 * alarm is set by klogin and kpasswd only so ignore for
159 * NT
160 */
161
162#ifndef AFS_NT40_ENV
163 { /* Rx uses timers, save to be safe */
164 if (rx_socket) {
165 /* don't reset alarms, rx already running */
166 remainingTime = 0;
167 } else
168 remainingTime = alarm(0);
169 }
170#endif
171
172#if !defined(AFS_NT40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_USR_LINUX20_ENV) && (!defined(AFS_XBSD_ENV) || defined(AFS_FBSD_ENV))
173 /* handle smoothly the case where no AFS system calls exists (yet) */
174 old = signal(SIGSYS12, SIG_IGN((__sighandler_t *)1));
Value stored to 'old' is never read
175#endif
176#ifdef AFS_DECOSF_ENV
177 (void)signal(SIGTRAP5, SIG_IGN((__sighandler_t *)1));
178#endif /* AFS_DECOSF_ENV */
179 if (instance == 0)
180 instance = "";
181 if (flags & KA_USERAUTH_ONLY_VERIFY0x040000) {
182 code = ka_VerifyUserToken(name, instance, realm, &key);
183 if (code == KABADREQUEST(180490L)) {
184 DES_string_to_keyhc_DES_string_to_key(password, ktc_to_cblockptr(&key));
185 code = ka_VerifyUserToken(name, instance, realm, &key);
186 }
187 } else {
188#ifdef AFS_DUX40_ENV
189 if (flags & KA_USERAUTH_DOSETPAG0x010000)
190 afs_setpag();
191#else
192#if !defined(UKERNEL1) && !defined(AFS_NT40_ENV)
193 if (flags & KA_USERAUTH_DOSETPAG0x010000)
194 setpag();
195#endif
196#endif
197 if (flags & KA_USERAUTH_DOSETPAG20x020000)
198 dosetpag = 1;
199#ifdef AFS_KERBEROS_ENV
200 if ((flags & KA_USERAUTH_DOSETPAG0x010000) || dosetpag)
201 ktc_newpag();
202#endif
203 if (lifetime == 0)
204 lifetime = MAXKTCTICKETLIFETIME(30*24*3600);
205 code =
206 GetTickets(name, instance, realm, &key, lifetime,
207 password_expires, dosetpag);
208 if (code == KABADREQUEST(180490L)) {
209 DES_string_to_keyhc_DES_string_to_key(password, ktc_to_cblockptr(&key));
210 code =
211 GetTickets(name, instance, realm, &key, lifetime,
212 password_expires, dosetpag);
213 }
214 }
215
216#ifndef AFS_NT40_ENV
217 if (remainingTime) {
218 pr_End();
219 rx_Finalize();
220 alarm(remainingTime); /* restore timer, if any */
221 }
222#endif
223
224 if (code && reasonP)
225 switch (code) {
226 case KABADREQUEST(180490L):
227 *reasonP = "password was incorrect";
228 break;
229 case KAUBIKCALL(180498L):
230 *reasonP = "Authentication Server was unavailable";
231 break;
232 default:
233 *reasonP = (char *)afs_error_message(code);
234 }
235 return code;
236}
237
238/* For backward compatibility */
239afs_int32
240ka_UserAuthenticate(char *name, char *instance, char *realm, char *password,
241 int doSetPAG, char **reasonP)
242{
243 return ka_UserAuthenticateGeneral(KA_USERAUTH_VERSION1 +
244 ((doSetPAG) ? KA_USERAUTH_DOSETPAG0x010000 : 0),
245 name, instance, realm, password,
246 /*lifetime */ 0, /*spare1,2 */ 0, 0,
247 reasonP);
248}
249
250#if !defined(UKERNEL1)
251afs_int32
252ka_UserReadPassword(char *prompt, char *password, int plen, char **reasonP)
253{
254 afs_int32 code = 0;
255
256 if (reasonP)
257 *reasonP = "";
258 code = ka_Init(0);
259 if (code)
260 return code;
261 code = UI_UTIL_read_pw_stringhc_UI_UTIL_read_pw_string(password, plen, prompt, 0);
262 if (code)
263 code = KAREADPW(180495L);
264 else if (strlen(password) == 0)
265 code = KANULLPASSWORD(180517L);
266 else
267 return 0;
268
269 if (reasonP) {
270 *reasonP = (char *)afs_error_message(code);
271 }
272 return code;
273}
274#endif /* !defined(UKERNEL) */
275
276afs_int32
277ka_VerifyUserPassword(afs_int32 version, char *name, char *instance,
278 char *realm, char *password, int spare, char **reasonP)
279{
280 afs_int32 pwexpires;
281
282 version &= KA_USERAUTH_VERSION_MASK0x00ffff;
283 return ka_UserAuthenticateGeneral(version | KA_USERAUTH_ONLY_VERIFY0x040000, name,
284 instance, realm, password, 0,
285 &pwexpires, spare, reasonP);
286}