Annotation of src/usr.bin/ssh/auth2.c, Revision 1.31
1.1 markus 1: /*
2: * Copyright (c) 2000 Markus Friedl. All rights reserved.
3: *
4: * Redistribution and use in source and binary forms, with or without
5: * modification, are permitted provided that the following conditions
6: * are met:
7: * 1. Redistributions of source code must retain the above copyright
8: * notice, this list of conditions and the following disclaimer.
9: * 2. Redistributions in binary form must reproduce the above copyright
10: * notice, this list of conditions and the following disclaimer in the
11: * documentation and/or other materials provided with the distribution.
12: *
13: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: */
1.14 deraadt 24:
1.1 markus 25: #include "includes.h"
1.31 ! markus 26: RCSID("$OpenBSD: auth2.c,v 1.30 2001/01/20 15:55:20 markus Exp $");
1.1 markus 27:
28: #include <openssl/dsa.h>
29: #include <openssl/rsa.h>
30: #include <openssl/evp.h>
31:
32: #include "xmalloc.h"
33: #include "rsa.h"
34: #include "ssh.h"
35: #include "pty.h"
36: #include "packet.h"
37: #include "buffer.h"
38: #include "servconf.h"
39: #include "compat.h"
40: #include "channels.h"
41: #include "bufaux.h"
42: #include "ssh2.h"
43: #include "auth.h"
44: #include "session.h"
45: #include "dispatch.h"
46: #include "auth.h"
47: #include "key.h"
48: #include "kex.h"
1.29 markus 49: #include "pathnames.h"
1.1 markus 50:
51: #include "uidswap.h"
1.10 markus 52: #include "auth-options.h"
1.1 markus 53:
54: /* import */
55: extern ServerOptions options;
1.23 markus 56: extern u_char *session_id2;
1.1 markus 57: extern int session_id2_len;
58:
1.18 markus 59: static Authctxt *x_authctxt = NULL;
60: static int one = 1;
61:
62: typedef struct Authmethod Authmethod;
63: struct Authmethod {
64: char *name;
65: int (*userauth)(Authctxt *authctxt);
66: int *enabled;
67: };
68:
1.1 markus 69: /* protocol */
70:
1.15 markus 71: void input_service_request(int type, int plen, void *ctxt);
72: void input_userauth_request(int type, int plen, void *ctxt);
73: void protocol_error(int type, int plen, void *ctxt);
1.1 markus 74:
75: /* helper */
1.18 markus 76: Authmethod *authmethod_lookup(const char *name);
77: struct passwd *pwcopy(struct passwd *pw);
1.21 markus 78: int user_key_allowed(struct passwd *pw, Key *key);
1.18 markus 79: char *authmethods_get(void);
1.1 markus 80:
1.18 markus 81: /* auth */
1.25 markus 82: void userauth_banner(void);
1.18 markus 83: int userauth_none(Authctxt *authctxt);
84: int userauth_passwd(Authctxt *authctxt);
85: int userauth_pubkey(Authctxt *authctxt);
86: int userauth_kbdint(Authctxt *authctxt);
87:
88: Authmethod authmethods[] = {
89: {"none",
90: userauth_none,
91: &one},
92: {"publickey",
93: userauth_pubkey,
1.21 markus 94: &options.pubkey_authentication},
1.18 markus 95: {"keyboard-interactive",
96: userauth_kbdint,
97: &options.kbd_interactive_authentication},
98: {"password",
99: userauth_passwd,
100: &options.password_authentication},
101: {NULL, NULL, NULL}
1.1 markus 102: };
103:
104: /*
1.18 markus 105: * loop until authctxt->success == TRUE
1.1 markus 106: */
107:
108: void
109: do_authentication2()
110: {
1.28 markus 111: Authctxt *authctxt = authctxt_new();
112:
1.18 markus 113: x_authctxt = authctxt; /*XXX*/
114:
1.26 markus 115: #ifdef AFS
116: /* If machine has AFS, set process authentication group. */
117: if (k_hasafs()) {
118: k_setpag();
119: k_unlog();
120: }
1.5 djm 121: #endif
1.1 markus 122: dispatch_init(&protocol_error);
123: dispatch_set(SSH2_MSG_SERVICE_REQUEST, &input_service_request);
1.18 markus 124: dispatch_run(DISPATCH_BLOCK, &authctxt->success, authctxt);
1.28 markus 125: do_authenticated2(authctxt);
1.1 markus 126: }
127:
128: void
1.15 markus 129: protocol_error(int type, int plen, void *ctxt)
1.1 markus 130: {
131: log("auth: protocol error: type %d plen %d", type, plen);
132: packet_start(SSH2_MSG_UNIMPLEMENTED);
133: packet_put_int(0);
134: packet_send();
135: packet_write_wait();
136: }
137:
138: void
1.15 markus 139: input_service_request(int type, int plen, void *ctxt)
1.1 markus 140: {
1.18 markus 141: Authctxt *authctxt = ctxt;
1.23 markus 142: u_int len;
1.1 markus 143: int accept = 0;
144: char *service = packet_get_string(&len);
145: packet_done();
146:
1.18 markus 147: if (authctxt == NULL)
148: fatal("input_service_request: no authctxt");
149:
1.1 markus 150: if (strcmp(service, "ssh-userauth") == 0) {
1.18 markus 151: if (!authctxt->success) {
1.1 markus 152: accept = 1;
153: /* now we can handle user-auth requests */
154: dispatch_set(SSH2_MSG_USERAUTH_REQUEST, &input_userauth_request);
155: }
156: }
157: /* XXX all other service requests are denied */
158:
159: if (accept) {
160: packet_start(SSH2_MSG_SERVICE_ACCEPT);
161: packet_put_cstring(service);
162: packet_send();
163: packet_write_wait();
164: } else {
165: debug("bad service request %s", service);
166: packet_disconnect("bad service request %s", service);
167: }
168: xfree(service);
169: }
170:
171: void
1.15 markus 172: input_userauth_request(int type, int plen, void *ctxt)
1.1 markus 173: {
1.18 markus 174: Authctxt *authctxt = ctxt;
175: Authmethod *m = NULL;
1.28 markus 176: char *user, *service, *method, *style = NULL;
1.1 markus 177: int authenticated = 0;
178:
1.18 markus 179: if (authctxt == NULL)
180: fatal("input_userauth_request: no authctxt");
1.1 markus 181:
1.18 markus 182: user = packet_get_string(NULL);
183: service = packet_get_string(NULL);
184: method = packet_get_string(NULL);
1.1 markus 185: debug("userauth-request for user %s service %s method %s", user, service, method);
1.24 markus 186: debug("attempt %d failures %d", authctxt->attempt, authctxt->failures);
1.1 markus 187:
1.28 markus 188: if ((style = strchr(user, ':')) != NULL)
189: *style++ = 0;
190:
1.24 markus 191: if (authctxt->attempt++ == 0) {
1.18 markus 192: /* setup auth context */
193: struct passwd *pw = NULL;
194: setproctitle("%s", user);
195: pw = getpwnam(user);
196: if (pw && allowed_user(pw) && strcmp(service, "ssh-connection")==0) {
197: authctxt->pw = pwcopy(pw);
198: authctxt->valid = 1;
199: debug2("input_userauth_request: setting up authctxt for %s", user);
200: } else {
201: log("input_userauth_request: illegal user %s", user);
202: }
203: authctxt->user = xstrdup(user);
204: authctxt->service = xstrdup(service);
1.28 markus 205: authctxt->style = style ? xstrdup(style) : NULL; /* currently unused */
1.18 markus 206: } else if (authctxt->valid) {
207: if (strcmp(user, authctxt->user) != 0 ||
208: strcmp(service, authctxt->service) != 0) {
209: log("input_userauth_request: missmatch: (%s,%s)!=(%s,%s)",
210: user, service, authctxt->user, authctxt->service);
211: authctxt->valid = 0;
1.1 markus 212: }
213: }
1.28 markus 214: /* reset state */
215: dispatch_set(SSH2_MSG_USERAUTH_INFO_RESPONSE, &protocol_error);
216: authctxt->postponed = 0;
1.18 markus 217:
1.28 markus 218: /* try to authenticate user */
1.18 markus 219: m = authmethod_lookup(method);
220: if (m != NULL) {
221: debug2("input_userauth_request: try method %s", method);
222: authenticated = m->userauth(authctxt);
223: }
1.28 markus 224: if (!authctxt->valid && authenticated)
225: fatal("INTERNAL ERROR: authenticated invalid user %s",
226: authctxt->user);
1.18 markus 227:
228: /* Special handling for root */
1.28 markus 229: if (authenticated && authctxt->pw->pw_uid == 0 && !auth_root_allowed())
1.3 markus 230: authenticated = 0;
231:
1.18 markus 232: /* Log before sending the reply */
1.28 markus 233: auth_log(authctxt, authenticated, method, " ssh2");
234:
235: if (!authctxt->postponed)
236: userauth_reply(authctxt, authenticated);
1.18 markus 237:
238: xfree(service);
239: xfree(user);
240: xfree(method);
241: }
242:
1.25 markus 243: void
244: userauth_banner(void)
245: {
246: struct stat st;
247: char *banner = NULL;
248: off_t len, n;
249: int fd;
250:
251: if (options.banner == NULL || (datafellows & SSH_BUG_BANNER))
252: return;
253: if ((fd = open(options.banner, O_RDONLY)) < 0) {
254: error("userauth_banner: open %s failed: %s",
255: options.banner, strerror(errno));
256: return;
257: }
258: if (fstat(fd, &st) < 0)
259: goto done;
260: len = st.st_size;
261: banner = xmalloc(len + 1);
262: if ((n = read(fd, banner, len)) < 0)
263: goto done;
264: banner[n] = '\0';
265: packet_start(SSH2_MSG_USERAUTH_BANNER);
266: packet_put_cstring(banner);
267: packet_put_cstring(""); /* language, unused */
268: packet_send();
269: debug("userauth_banner: sent");
270: done:
271: if (banner)
272: xfree(banner);
273: close(fd);
274: return;
275: }
1.18 markus 276:
277: void
278: userauth_reply(Authctxt *authctxt, int authenticated)
279: {
1.24 markus 280: char *methods;
1.28 markus 281:
1.3 markus 282: /* XXX todo: check if multiple auth methods are needed */
1.28 markus 283: if (authenticated) {
1.1 markus 284: /* turn off userauth */
285: dispatch_set(SSH2_MSG_USERAUTH_REQUEST, &protocol_error);
286: packet_start(SSH2_MSG_USERAUTH_SUCCESS);
287: packet_send();
288: packet_write_wait();
289: /* now we can break out */
1.18 markus 290: authctxt->success = 1;
1.28 markus 291: } else {
292: if (authctxt->failures++ > AUTH_FAIL_MAX)
293: packet_disconnect(AUTH_FAIL_MSG, authctxt->user);
1.24 markus 294: methods = authmethods_get();
1.1 markus 295: packet_start(SSH2_MSG_USERAUTH_FAILURE);
1.18 markus 296: packet_put_cstring(methods);
297: packet_put_char(0); /* XXX partial success, unused */
1.1 markus 298: packet_send();
299: packet_write_wait();
1.18 markus 300: xfree(methods);
1.1 markus 301: }
302: }
303:
304: int
1.18 markus 305: userauth_none(Authctxt *authctxt)
1.1 markus 306: {
1.18 markus 307: /* disable method "none", only allowed one time */
308: Authmethod *m = authmethod_lookup("none");
309: if (m != NULL)
310: m->enabled = NULL;
1.1 markus 311: packet_done();
1.25 markus 312: userauth_banner();
1.18 markus 313: return authctxt->valid ? auth_password(authctxt->pw, "") : 0;
1.1 markus 314: }
1.18 markus 315:
1.1 markus 316: int
1.18 markus 317: userauth_passwd(Authctxt *authctxt)
1.1 markus 318: {
319: char *password;
320: int authenticated = 0;
321: int change;
1.23 markus 322: u_int len;
1.1 markus 323: change = packet_get_char();
324: if (change)
325: log("password change not supported");
326: password = packet_get_string(&len);
327: packet_done();
1.18 markus 328: if (authctxt->valid &&
329: auth_password(authctxt->pw, password) == 1)
1.1 markus 330: authenticated = 1;
331: memset(password, 0, len);
332: xfree(password);
333: return authenticated;
334: }
1.18 markus 335:
336: int
337: userauth_kbdint(Authctxt *authctxt)
338: {
339: int authenticated = 0;
340: char *lang = NULL;
341: char *devs = NULL;
342:
343: lang = packet_get_string(NULL);
344: devs = packet_get_string(NULL);
345: packet_done();
346:
347: debug("keyboard-interactive language %s devs %s", lang, devs);
1.28 markus 348:
349: authenticated = auth2_challenge(authctxt, devs);
350:
1.18 markus 351: xfree(lang);
352: xfree(devs);
353: return authenticated;
354: }
355:
1.1 markus 356: int
1.18 markus 357: userauth_pubkey(Authctxt *authctxt)
1.1 markus 358: {
359: Buffer b;
360: Key *key;
361: char *pkalg, *pkblob, *sig;
1.23 markus 362: u_int alen, blen, slen;
1.21 markus 363: int have_sig, pktype;
1.1 markus 364: int authenticated = 0;
365:
1.18 markus 366: if (!authctxt->valid) {
367: debug2("userauth_pubkey: disabled because of invalid user");
1.8 markus 368: return 0;
369: }
1.1 markus 370: have_sig = packet_get_char();
1.22 markus 371: if (datafellows & SSH_BUG_PKAUTH) {
372: debug2("userauth_pubkey: SSH_BUG_PKAUTH");
373: /* no explicit pkalg given */
374: pkblob = packet_get_string(&blen);
375: buffer_init(&b);
376: buffer_append(&b, pkblob, blen);
377: /* so we have to extract the pkalg from the pkblob */
378: pkalg = buffer_get_string(&b, &alen);
379: buffer_free(&b);
380: } else {
381: pkalg = packet_get_string(&alen);
382: pkblob = packet_get_string(&blen);
383: }
1.21 markus 384: pktype = key_type_from_name(pkalg);
385: if (pktype == KEY_UNSPEC) {
1.22 markus 386: /* this is perfectly legal */
387: log("userauth_pubkey: unsupported public key algorithm: %s", pkalg);
1.1 markus 388: xfree(pkalg);
1.22 markus 389: xfree(pkblob);
1.1 markus 390: return 0;
391: }
1.21 markus 392: key = key_from_blob(pkblob, blen);
1.2 markus 393: if (key != NULL) {
394: if (have_sig) {
395: sig = packet_get_string(&slen);
396: packet_done();
397: buffer_init(&b);
1.20 markus 398: if (datafellows & SSH_OLD_SESSIONID) {
399: buffer_append(&b, session_id2, session_id2_len);
400: } else {
1.11 markus 401: buffer_put_string(&b, session_id2, session_id2_len);
402: }
1.9 markus 403: /* reconstruct packet */
1.2 markus 404: buffer_put_char(&b, SSH2_MSG_USERAUTH_REQUEST);
1.18 markus 405: buffer_put_cstring(&b, authctxt->user);
1.9 markus 406: buffer_put_cstring(&b,
1.22 markus 407: datafellows & SSH_BUG_PKSERVICE ?
1.9 markus 408: "ssh-userauth" :
1.18 markus 409: authctxt->service);
1.22 markus 410: if (datafellows & SSH_BUG_PKAUTH) {
411: buffer_put_char(&b, have_sig);
412: } else {
413: buffer_put_cstring(&b, "publickey");
414: buffer_put_char(&b, have_sig);
415: buffer_put_cstring(&b, key_ssh_name(key));
416: }
1.9 markus 417: buffer_put_string(&b, pkblob, blen);
1.21 markus 418: #ifdef DEBUG_PK
1.2 markus 419: buffer_dump(&b);
1.1 markus 420: #endif
1.2 markus 421: /* test for correct signature */
1.21 markus 422: if (user_key_allowed(authctxt->pw, key) &&
423: key_verify(key, sig, slen, buffer_ptr(&b), buffer_len(&b)) == 1)
1.2 markus 424: authenticated = 1;
425: buffer_clear(&b);
426: xfree(sig);
427: } else {
1.18 markus 428: debug("test whether pkalg/pkblob are acceptable");
1.2 markus 429: packet_done();
1.18 markus 430:
1.2 markus 431: /* XXX fake reply and always send PK_OK ? */
1.6 markus 432: /*
433: * XXX this allows testing whether a user is allowed
434: * to login: if you happen to have a valid pubkey this
435: * message is sent. the message is NEVER sent at all
436: * if a user is not allowed to login. is this an
437: * issue? -markus
438: */
1.21 markus 439: if (user_key_allowed(authctxt->pw, key)) {
1.2 markus 440: packet_start(SSH2_MSG_USERAUTH_PK_OK);
441: packet_put_string(pkalg, alen);
442: packet_put_string(pkblob, blen);
443: packet_send();
444: packet_write_wait();
445: authenticated = -1;
446: }
1.1 markus 447: }
1.17 markus 448: if (authenticated != 1)
449: auth_clear_options();
1.2 markus 450: key_free(key);
1.1 markus 451: }
1.21 markus 452: debug2("userauth_pubkey: authenticated %d pkalg %s", authenticated, pkalg);
1.1 markus 453: xfree(pkalg);
454: xfree(pkblob);
455: return authenticated;
456: }
457:
1.18 markus 458: /* get current user */
1.1 markus 459:
460: struct passwd*
461: auth_get_user(void)
462: {
1.18 markus 463: return (x_authctxt != NULL && x_authctxt->valid) ? x_authctxt->pw : NULL;
1.1 markus 464: }
465:
1.18 markus 466: #define DELIM ","
467:
468: char *
469: authmethods_get(void)
1.1 markus 470: {
1.18 markus 471: Authmethod *method = NULL;
1.23 markus 472: u_int size = 0;
1.18 markus 473: char *list;
1.1 markus 474:
1.18 markus 475: for (method = authmethods; method->name != NULL; method++) {
476: if (strcmp(method->name, "none") == 0)
477: continue;
478: if (method->enabled != NULL && *(method->enabled) != 0) {
479: if (size != 0)
480: size += strlen(DELIM);
481: size += strlen(method->name);
1.1 markus 482: }
1.18 markus 483: }
484: size++; /* trailing '\0' */
485: list = xmalloc(size);
486: list[0] = '\0';
487:
488: for (method = authmethods; method->name != NULL; method++) {
489: if (strcmp(method->name, "none") == 0)
490: continue;
491: if (method->enabled != NULL && *(method->enabled) != 0) {
492: if (list[0] != '\0')
493: strlcat(list, DELIM, size);
494: strlcat(list, method->name, size);
1.1 markus 495: }
496: }
1.18 markus 497: return list;
498: }
499:
500: Authmethod *
501: authmethod_lookup(const char *name)
502: {
503: Authmethod *method = NULL;
504: if (name != NULL)
505: for (method = authmethods; method->name != NULL; method++)
506: if (method->enabled != NULL &&
507: *(method->enabled) != 0 &&
508: strcmp(name, method->name) == 0)
509: return method;
510: debug2("Unrecognized authentication method name: %s", name ? name : "NULL");
511: return NULL;
1.1 markus 512: }
513:
514: /* return 1 if user allows given key */
515: int
1.21 markus 516: user_key_allowed(struct passwd *pw, Key *key)
1.1 markus 517: {
1.31 ! markus 518: char line[8192], file[MAXPATHLEN];
1.1 markus 519: int found_key = 0;
520: FILE *f;
1.23 markus 521: u_long linenum = 0;
1.1 markus 522: struct stat st;
523: Key *found;
524:
1.18 markus 525: if (pw == NULL)
526: return 0;
527:
1.1 markus 528: /* Temporarily use the user's uid. */
529: temporarily_use_uid(pw->pw_uid);
530:
531: /* The authorized keys. */
532: snprintf(file, sizeof file, "%.500s/%.100s", pw->pw_dir,
1.29 markus 533: _PATH_SSH_USER_PERMITTED_KEYS2);
1.1 markus 534:
535: /* Fail quietly if file does not exist */
536: if (stat(file, &st) < 0) {
537: /* Restore the privileged uid. */
538: restore_uid();
539: return 0;
540: }
541: /* Open the file containing the authorized keys. */
542: f = fopen(file, "r");
543: if (!f) {
544: /* Restore the privileged uid. */
545: restore_uid();
546: return 0;
547: }
548: if (options.strict_modes) {
549: int fail = 0;
550: char buf[1024];
551: /* Check open file in order to avoid open/stat races */
552: if (fstat(fileno(f), &st) < 0 ||
553: (st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
554: (st.st_mode & 022) != 0) {
1.16 markus 555: snprintf(buf, sizeof buf,
556: "%s authentication refused for %.100s: "
557: "bad ownership or modes for '%s'.",
558: key_type(key), pw->pw_name, file);
1.1 markus 559: fail = 1;
560: } else {
1.29 markus 561: /* Check path to _PATH_SSH_USER_PERMITTED_KEYS */
1.1 markus 562: int i;
563: static const char *check[] = {
1.29 markus 564: "", _PATH_SSH_USER_DIR, NULL
1.1 markus 565: };
566: for (i = 0; check[i]; i++) {
567: snprintf(line, sizeof line, "%.500s/%.100s",
568: pw->pw_dir, check[i]);
569: if (stat(line, &st) < 0 ||
570: (st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
571: (st.st_mode & 022) != 0) {
572: snprintf(buf, sizeof buf,
1.16 markus 573: "%s authentication refused for %.100s: "
1.1 markus 574: "bad ownership or modes for '%s'.",
1.16 markus 575: key_type(key), pw->pw_name, line);
1.1 markus 576: fail = 1;
577: break;
578: }
579: }
580: }
581: if (fail) {
582: fclose(f);
1.12 todd 583: log("%s",buf);
1.1 markus 584: restore_uid();
585: return 0;
586: }
587: }
588: found_key = 0;
1.16 markus 589: found = key_new(key->type);
1.1 markus 590:
591: while (fgets(line, sizeof(line), f)) {
1.10 markus 592: char *cp, *options = NULL;
1.1 markus 593: linenum++;
594: /* Skip leading whitespace, empty and comment lines. */
595: for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
596: ;
597: if (!*cp || *cp == '\n' || *cp == '#')
598: continue;
1.10 markus 599:
1.21 markus 600: if (key_read(found, &cp) == -1) {
1.10 markus 601: /* no key? check if there are options for this key */
602: int quoted = 0;
1.21 markus 603: debug2("user_key_allowed: check options: '%s'", cp);
1.10 markus 604: options = cp;
605: for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
606: if (*cp == '\\' && cp[1] == '"')
607: cp++; /* Skip both */
608: else if (*cp == '"')
609: quoted = !quoted;
610: }
611: /* Skip remaining whitespace. */
612: for (; *cp == ' ' || *cp == '\t'; cp++)
613: ;
1.21 markus 614: if (key_read(found, &cp) == -1) {
615: debug2("user_key_allowed: advance: '%s'", cp);
1.10 markus 616: /* still no key? advance to next line*/
617: continue;
618: }
619: }
620: if (key_equal(found, key) &&
1.30 markus 621: auth_parse_options(pw, options, file, linenum) == 1) {
1.1 markus 622: found_key = 1;
623: debug("matching key found: file %s, line %ld",
624: file, linenum);
625: break;
626: }
627: }
628: restore_uid();
629: fclose(f);
630: key_free(found);
631: return found_key;
632: }