1 /* $NetBSD: auth.c,v 1.8 2013/11/08 19:18:24 christos Exp $ */ 2 /* $OpenBSD: auth.c,v 1.103 2013/05/19 02:42:42 djm Exp $ */ 3 /* 4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #include "includes.h" 28 __RCSID("$NetBSD: auth.c,v 1.8 2013/11/08 19:18:24 christos Exp $"); 29 #include <sys/types.h> 30 #include <sys/stat.h> 31 #include <sys/param.h> 32 33 #include <errno.h> 34 #include <fcntl.h> 35 #include <libgen.h> 36 #include <login_cap.h> 37 #include <paths.h> 38 #include <pwd.h> 39 #include <stdarg.h> 40 #include <stdio.h> 41 #include <string.h> 42 #include <unistd.h> 43 44 #include "xmalloc.h" 45 #include "match.h" 46 #include "groupaccess.h" 47 #include "log.h" 48 #include "buffer.h" 49 #include "servconf.h" 50 #include "key.h" 51 #include "hostfile.h" 52 #include "auth.h" 53 #include "auth-options.h" 54 #include "canohost.h" 55 #include "uidswap.h" 56 #include "misc.h" 57 #include "packet.h" 58 #ifdef GSSAPI 59 #include "ssh-gss.h" 60 #endif 61 #include "authfile.h" 62 #include "monitor_wrap.h" 63 #include "krl.h" 64 #include "compat.h" 65 66 #ifdef HAVE_LOGIN_CAP 67 #include <login_cap.h> 68 #endif 69 70 /* import */ 71 extern ServerOptions options; 72 extern int use_privsep; 73 74 /* Debugging messages */ 75 Buffer auth_debug; 76 int auth_debug_init; 77 78 /* 79 * Check if the user is allowed to log in via ssh. If user is listed 80 * in DenyUsers or one of user's groups is listed in DenyGroups, false 81 * will be returned. If AllowUsers isn't empty and user isn't listed 82 * there, or if AllowGroups isn't empty and one of user's groups isn't 83 * listed there, false will be returned. 84 * If the user's shell is not executable, false will be returned. 85 * Otherwise true is returned. 86 */ 87 int 88 allowed_user(struct passwd * pw) 89 { 90 #ifdef HAVE_LOGIN_CAP 91 extern login_cap_t *lc; 92 int match_name, match_ip; 93 char *cap_hlist, *hp; 94 #endif 95 struct stat st; 96 const char *hostname = NULL, *ipaddr = NULL; 97 u_int i; 98 99 /* Shouldn't be called if pw is NULL, but better safe than sorry... */ 100 if (!pw || !pw->pw_name) 101 return 0; 102 103 #ifdef HAVE_LOGIN_CAP 104 hostname = get_canonical_hostname(1); 105 ipaddr = get_remote_ipaddr(); 106 107 lc = login_getclass(pw->pw_class); 108 109 /* 110 * Check the deny list. 111 */ 112 cap_hlist = login_getcapstr(lc, "host.deny", NULL, NULL); 113 if (cap_hlist != NULL) { 114 hp = strtok(cap_hlist, ","); 115 while (hp != NULL) { 116 match_name = match_hostname(hostname, 117 hp, strlen(hp)); 118 match_ip = match_hostname(ipaddr, 119 hp, strlen(hp)); 120 /* 121 * Only a positive match here causes a "deny". 122 */ 123 if (match_name > 0 || match_ip > 0) { 124 free(cap_hlist); 125 login_close(lc); 126 return 0; 127 } 128 hp = strtok(NULL, ","); 129 } 130 free(cap_hlist); 131 } 132 133 /* 134 * Check the allow list. If the allow list exists, and the 135 * remote host is not in it, the user is implicitly denied. 136 */ 137 cap_hlist = login_getcapstr(lc, "host.allow", NULL, NULL); 138 if (cap_hlist != NULL) { 139 hp = strtok(cap_hlist, ","); 140 if (hp == NULL) { 141 /* Just in case there's an empty string... */ 142 free(cap_hlist); 143 login_close(lc); 144 return 0; 145 } 146 while (hp != NULL) { 147 match_name = match_hostname(hostname, 148 hp, strlen(hp)); 149 match_ip = match_hostname(ipaddr, 150 hp, strlen(hp)); 151 /* 152 * Negative match causes an immediate "deny". 153 * Positive match causes us to break out 154 * of the loop (allowing a fallthrough). 155 */ 156 if (match_name < 0 || match_ip < 0) { 157 free(cap_hlist); 158 login_close(lc); 159 return 0; 160 } 161 if (match_name > 0 || match_ip > 0) 162 break; 163 hp = strtok(NULL, ","); 164 } 165 free(cap_hlist); 166 if (hp == NULL) { 167 login_close(lc); 168 return 0; 169 } 170 } 171 172 login_close(lc); 173 #endif 174 175 #ifdef USE_PAM 176 if (!options.use_pam) { 177 #endif 178 /* 179 * password/account expiration. 180 */ 181 if (pw->pw_change || pw->pw_expire) { 182 struct timeval tv; 183 184 (void)gettimeofday(&tv, (struct timezone *)NULL); 185 if (pw->pw_expire) { 186 if (tv.tv_sec >= pw->pw_expire) { 187 logit("User %.100s not allowed because account has expired", 188 pw->pw_name); 189 return 0; /* expired */ 190 } 191 } 192 #ifdef _PASSWORD_CHGNOW 193 if (pw->pw_change == _PASSWORD_CHGNOW) { 194 logit("User %.100s not allowed because password needs to be changed", 195 pw->pw_name); 196 197 return 0; /* can't force password change (yet) */ 198 } 199 #endif 200 if (pw->pw_change) { 201 if (tv.tv_sec >= pw->pw_change) { 202 logit("User %.100s not allowed because password has expired", 203 pw->pw_name); 204 return 0; /* expired */ 205 } 206 } 207 } 208 #ifdef USE_PAM 209 } 210 #endif 211 212 /* 213 * Deny if shell does not exist or is not executable unless we 214 * are chrooting. 215 */ 216 /* 217 * XXX Should check to see if it is executable by the 218 * XXX requesting user. --thorpej 219 */ 220 if (options.chroot_directory == NULL || 221 strcasecmp(options.chroot_directory, "none") == 0) { 222 char *shell = xstrdup((pw->pw_shell[0] == '\0') ? 223 _PATH_BSHELL : pw->pw_shell); /* empty = /bin/sh */ 224 225 if (stat(shell, &st) != 0) { 226 logit("User %.100s not allowed because shell %.100s " 227 "does not exist", pw->pw_name, shell); 228 free(shell); 229 return 0; 230 } 231 if (S_ISREG(st.st_mode) == 0 || 232 (st.st_mode & (S_IXOTH|S_IXUSR|S_IXGRP)) == 0) { 233 logit("User %.100s not allowed because shell %.100s " 234 "is not executable", pw->pw_name, shell); 235 free(shell); 236 return 0; 237 } 238 free(shell); 239 } 240 /* 241 * XXX Consider nuking {Allow,Deny}{Users,Groups}. We have the 242 * XXX login_cap(3) mechanism which covers all other types of 243 * XXX logins, too. 244 */ 245 246 if (options.num_deny_users > 0 || options.num_allow_users > 0 || 247 options.num_deny_groups > 0 || options.num_allow_groups > 0) { 248 hostname = get_canonical_hostname(options.use_dns); 249 ipaddr = get_remote_ipaddr(); 250 } 251 252 /* Return false if user is listed in DenyUsers */ 253 if (options.num_deny_users > 0) { 254 for (i = 0; i < options.num_deny_users; i++) 255 if (match_user(pw->pw_name, hostname, ipaddr, 256 options.deny_users[i])) { 257 logit("User %.100s from %.100s not allowed " 258 "because listed in DenyUsers", 259 pw->pw_name, hostname); 260 return 0; 261 } 262 } 263 /* Return false if AllowUsers isn't empty and user isn't listed there */ 264 if (options.num_allow_users > 0) { 265 for (i = 0; i < options.num_allow_users; i++) 266 if (match_user(pw->pw_name, hostname, ipaddr, 267 options.allow_users[i])) 268 break; 269 /* i < options.num_allow_users iff we break for loop */ 270 if (i >= options.num_allow_users) { 271 logit("User %.100s from %.100s not allowed because " 272 "not listed in AllowUsers", pw->pw_name, hostname); 273 return 0; 274 } 275 } 276 if (options.num_deny_groups > 0 || options.num_allow_groups > 0) { 277 /* Get the user's group access list (primary and supplementary) */ 278 if (ga_init(pw->pw_name, pw->pw_gid) == 0) { 279 logit("User %.100s from %.100s not allowed because " 280 "not in any group", pw->pw_name, hostname); 281 return 0; 282 } 283 284 /* Return false if one of user's groups is listed in DenyGroups */ 285 if (options.num_deny_groups > 0) 286 if (ga_match(options.deny_groups, 287 options.num_deny_groups)) { 288 ga_free(); 289 logit("User %.100s from %.100s not allowed " 290 "because a group is listed in DenyGroups", 291 pw->pw_name, hostname); 292 return 0; 293 } 294 /* 295 * Return false if AllowGroups isn't empty and one of user's groups 296 * isn't listed there 297 */ 298 if (options.num_allow_groups > 0) 299 if (!ga_match(options.allow_groups, 300 options.num_allow_groups)) { 301 ga_free(); 302 logit("User %.100s from %.100s not allowed " 303 "because none of user's groups are listed " 304 "in AllowGroups", pw->pw_name, hostname); 305 return 0; 306 } 307 ga_free(); 308 } 309 /* We found no reason not to let this user try to log on... */ 310 return 1; 311 } 312 313 void 314 auth_info(Authctxt *authctxt, const char *fmt, ...) 315 { 316 va_list ap; 317 int i; 318 319 free(authctxt->info); 320 authctxt->info = NULL; 321 322 va_start(ap, fmt); 323 i = vasprintf(&authctxt->info, fmt, ap); 324 va_end(ap); 325 326 if (i < 0 || authctxt->info == NULL) 327 fatal("vasprintf failed"); 328 } 329 330 void 331 auth_log(Authctxt *authctxt, int authenticated, int partial, 332 const char *method, const char *submethod) 333 { 334 void (*authlog) (const char *fmt,...) = verbose; 335 const char *authmsg; 336 337 if (use_privsep && !mm_is_monitor() && !authctxt->postponed) 338 return; 339 340 /* Raise logging level */ 341 if (authenticated == 1 || 342 !authctxt->valid || 343 authctxt->failures >= options.max_authtries / 2 || 344 strcmp(method, "password") == 0) 345 authlog = logit; 346 347 if (authctxt->postponed) 348 authmsg = "Postponed"; 349 else if (partial) 350 authmsg = "Partial"; 351 else 352 authmsg = authenticated ? "Accepted" : "Failed"; 353 354 authlog("%s %s%s%s for %s%.100s from %.200s port %d %s%s%s", 355 authmsg, 356 method, 357 submethod != NULL ? "/" : "", submethod == NULL ? "" : submethod, 358 authctxt->valid ? "" : "invalid user ", 359 authctxt->user, 360 get_remote_ipaddr(), 361 get_remote_port(), 362 compat20 ? "ssh2" : "ssh1", 363 authctxt->info != NULL ? ": " : "", 364 authctxt->info != NULL ? authctxt->info : ""); 365 free(authctxt->info); 366 authctxt->info = NULL; 367 } 368 369 /* 370 * Check whether root logins are disallowed. 371 */ 372 int 373 auth_root_allowed(const char *method) 374 { 375 switch (options.permit_root_login) { 376 case PERMIT_YES: 377 return 1; 378 case PERMIT_NO_PASSWD: 379 if (strcmp(method, "password") != 0) 380 return 1; 381 break; 382 case PERMIT_FORCED_ONLY: 383 if (forced_command) { 384 logit("Root login accepted for forced command."); 385 return 1; 386 } 387 break; 388 } 389 logit("ROOT LOGIN REFUSED FROM %.200s", get_remote_ipaddr()); 390 return 0; 391 } 392 393 394 /* 395 * Given a template and a passwd structure, build a filename 396 * by substituting % tokenised options. Currently, %% becomes '%', 397 * %h becomes the home directory and %u the username. 398 * 399 * This returns a buffer allocated by xmalloc. 400 */ 401 char * 402 expand_authorized_keys(const char *filename, struct passwd *pw) 403 { 404 char *file, ret[MAXPATHLEN]; 405 int i; 406 407 file = percent_expand(filename, "h", pw->pw_dir, 408 "u", pw->pw_name, (char *)NULL); 409 410 /* 411 * Ensure that filename starts anchored. If not, be backward 412 * compatible and prepend the '%h/' 413 */ 414 if (*file == '/') 415 return (file); 416 417 i = snprintf(ret, sizeof(ret), "%s/%s", pw->pw_dir, file); 418 if (i < 0 || (size_t)i >= sizeof(ret)) 419 fatal("expand_authorized_keys: path too long"); 420 free(file); 421 return (xstrdup(ret)); 422 } 423 424 char * 425 authorized_principals_file(struct passwd *pw) 426 { 427 if (options.authorized_principals_file == NULL || 428 strcasecmp(options.authorized_principals_file, "none") == 0) 429 return NULL; 430 return expand_authorized_keys(options.authorized_principals_file, pw); 431 } 432 433 /* return ok if key exists in sysfile or userfile */ 434 HostStatus 435 check_key_in_hostfiles(struct passwd *pw, Key *key, const char *host, 436 const char *sysfile, const char *userfile) 437 { 438 char *user_hostfile; 439 struct stat st; 440 HostStatus host_status; 441 struct hostkeys *hostkeys; 442 const struct hostkey_entry *found; 443 444 hostkeys = init_hostkeys(); 445 load_hostkeys(hostkeys, host, sysfile); 446 if (userfile != NULL) { 447 user_hostfile = tilde_expand_filename(userfile, pw->pw_uid); 448 if (options.strict_modes && 449 (stat(user_hostfile, &st) == 0) && 450 ((st.st_uid != 0 && st.st_uid != pw->pw_uid) || 451 (st.st_mode & 022) != 0)) { 452 logit("Authentication refused for %.100s: " 453 "bad owner or modes for %.200s", 454 pw->pw_name, user_hostfile); 455 auth_debug_add("Ignored %.200s: bad ownership or modes", 456 user_hostfile); 457 } else { 458 temporarily_use_uid(pw); 459 load_hostkeys(hostkeys, host, user_hostfile); 460 restore_uid(); 461 } 462 free(user_hostfile); 463 } 464 host_status = check_key_in_hostkeys(hostkeys, key, &found); 465 if (host_status == HOST_REVOKED) 466 error("WARNING: revoked key for %s attempted authentication", 467 found->host); 468 else if (host_status == HOST_OK) 469 debug("%s: key for %s found at %s:%ld", __func__, 470 found->host, found->file, found->line); 471 else 472 debug("%s: key for host %s not found", __func__, host); 473 474 free_hostkeys(hostkeys); 475 476 return host_status; 477 } 478 479 /* 480 * Check a given path for security. This is defined as all components 481 * of the path to the file must be owned by either the owner of 482 * of the file or root and no directories must be group or world writable. 483 * 484 * XXX Should any specific check be done for sym links ? 485 * 486 * Takes a file name, its stat information (preferably from fstat() to 487 * avoid races), the uid of the expected owner, their home directory and an 488 * error buffer plus max size as arguments. 489 * 490 * Returns 0 on success and -1 on failure 491 */ 492 int 493 auth_secure_path(const char *name, struct stat *stp, const char *pw_dir, 494 uid_t uid, char *err, size_t errlen) 495 { 496 char buf[MAXPATHLEN], homedir[MAXPATHLEN]; 497 char *cp; 498 int comparehome = 0; 499 struct stat st; 500 501 if (realpath(name, buf) == NULL) { 502 snprintf(err, errlen, "realpath %s failed: %s", name, 503 strerror(errno)); 504 return -1; 505 } 506 if (pw_dir != NULL && realpath(pw_dir, homedir) != NULL) 507 comparehome = 1; 508 509 if (!S_ISREG(stp->st_mode)) { 510 snprintf(err, errlen, "%s is not a regular file", buf); 511 return -1; 512 } 513 if ((stp->st_uid != 0 && stp->st_uid != uid) || 514 (stp->st_mode & 022) != 0) { 515 snprintf(err, errlen, "bad ownership or modes for file %s", 516 buf); 517 return -1; 518 } 519 520 /* for each component of the canonical path, walking upwards */ 521 for (;;) { 522 if ((cp = dirname(buf)) == NULL) { 523 snprintf(err, errlen, "dirname() failed"); 524 return -1; 525 } 526 strlcpy(buf, cp, sizeof(buf)); 527 528 if (stat(buf, &st) < 0 || 529 (st.st_uid != 0 && st.st_uid != uid) || 530 (st.st_mode & 022) != 0) { 531 snprintf(err, errlen, 532 "bad ownership or modes for directory %s", buf); 533 return -1; 534 } 535 536 /* If are past the homedir then we can stop */ 537 if (comparehome && strcmp(homedir, buf) == 0) 538 break; 539 540 /* 541 * dirname should always complete with a "/" path, 542 * but we can be paranoid and check for "." too 543 */ 544 if ((strcmp("/", buf) == 0) || (strcmp(".", buf) == 0)) 545 break; 546 } 547 return 0; 548 } 549 550 /* 551 * Version of secure_path() that accepts an open file descriptor to 552 * avoid races. 553 * 554 * Returns 0 on success and -1 on failure 555 */ 556 static int 557 secure_filename(FILE *f, const char *file, struct passwd *pw, 558 char *err, size_t errlen) 559 { 560 struct stat st; 561 562 /* check the open file to avoid races */ 563 if (fstat(fileno(f), &st) < 0) { 564 snprintf(err, errlen, "cannot stat file %s: %s", 565 file, strerror(errno)); 566 return -1; 567 } 568 return auth_secure_path(file, &st, pw->pw_dir, pw->pw_uid, err, errlen); 569 } 570 571 static FILE * 572 auth_openfile(const char *file, struct passwd *pw, int strict_modes, 573 int log_missing, const char *file_type) 574 { 575 char line[1024]; 576 struct stat st; 577 int fd; 578 FILE *f; 579 580 if ((fd = open(file, O_RDONLY|O_NONBLOCK)) == -1) { 581 if (log_missing || errno != ENOENT) 582 debug("Could not open %s '%s': %s", file_type, file, 583 strerror(errno)); 584 return NULL; 585 } 586 587 if (fstat(fd, &st) < 0) { 588 close(fd); 589 return NULL; 590 } 591 if (!S_ISREG(st.st_mode)) { 592 logit("User %s %s %s is not a regular file", 593 pw->pw_name, file_type, file); 594 close(fd); 595 return NULL; 596 } 597 unset_nonblock(fd); 598 if ((f = fdopen(fd, "r")) == NULL) { 599 close(fd); 600 return NULL; 601 } 602 if (strict_modes && 603 secure_filename(f, file, pw, line, sizeof(line)) != 0) { 604 fclose(f); 605 logit("Authentication refused: %s", line); 606 auth_debug_add("Ignored %s: %s", file_type, line); 607 return NULL; 608 } 609 610 return f; 611 } 612 613 614 FILE * 615 auth_openkeyfile(const char *file, struct passwd *pw, int strict_modes) 616 { 617 return auth_openfile(file, pw, strict_modes, 1, "authorized keys"); 618 } 619 620 FILE * 621 auth_openprincipals(const char *file, struct passwd *pw, int strict_modes) 622 { 623 return auth_openfile(file, pw, strict_modes, 0, 624 "authorized principals"); 625 } 626 627 struct passwd * 628 getpwnamallow(const char *user) 629 { 630 #ifdef HAVE_LOGIN_CAP 631 extern login_cap_t *lc; 632 #ifdef BSD_AUTH 633 auth_session_t *as; 634 #endif 635 #endif 636 struct passwd *pw; 637 struct connection_info *ci = get_connection_info(1, options.use_dns); 638 639 ci->user = user; 640 parse_server_match_config(&options, ci); 641 642 pw = getpwnam(user); 643 if (pw == NULL) { 644 logit("Invalid user %.100s from %.100s", 645 user, get_remote_ipaddr()); 646 return (NULL); 647 } 648 if (!allowed_user(pw)) 649 return (NULL); 650 #ifdef HAVE_LOGIN_CAP 651 if ((lc = login_getclass(pw->pw_class)) == NULL) { 652 debug("unable to get login class: %s", user); 653 return (NULL); 654 } 655 #ifdef BSD_AUTH 656 if ((as = auth_open()) == NULL || auth_setpwd(as, pw) != 0 || 657 auth_approval(as, lc, pw->pw_name, "ssh") <= 0) { 658 debug("Approval failure for %s", user); 659 pw = NULL; 660 } 661 if (as != NULL) 662 auth_close(as); 663 #endif 664 #endif 665 if (pw != NULL) 666 return (pwcopy(pw)); 667 return (NULL); 668 } 669 670 /* Returns 1 if key is revoked by revoked_keys_file, 0 otherwise */ 671 int 672 auth_key_is_revoked(Key *key) 673 { 674 char *key_fp; 675 676 if (options.revoked_keys_file == NULL) 677 return 0; 678 switch (ssh_krl_file_contains_key(options.revoked_keys_file, key)) { 679 case 0: 680 return 0; /* Not revoked */ 681 case -2: 682 break; /* Not a KRL */ 683 default: 684 goto revoked; 685 } 686 debug3("%s: treating %s as a key list", __func__, 687 options.revoked_keys_file); 688 switch (key_in_file(key, options.revoked_keys_file, 0)) { 689 case 0: 690 /* key not revoked */ 691 return 0; 692 case -1: 693 /* Error opening revoked_keys_file: refuse all keys */ 694 error("Revoked keys file is unreadable: refusing public key " 695 "authentication"); 696 return 1; 697 case 1: 698 revoked: 699 /* Key revoked */ 700 key_fp = key_fingerprint(key, SSH_FP_MD5, SSH_FP_HEX); 701 error("WARNING: authentication attempt with a revoked " 702 "%s key %s ", key_type(key), key_fp); 703 free(key_fp); 704 return 1; 705 } 706 fatal("key_in_file returned junk"); 707 } 708 709 void 710 auth_debug_add(const char *fmt,...) 711 { 712 char buf[1024]; 713 va_list args; 714 715 if (!auth_debug_init) 716 return; 717 718 va_start(args, fmt); 719 vsnprintf(buf, sizeof(buf), fmt, args); 720 va_end(args); 721 buffer_put_cstring(&auth_debug, buf); 722 } 723 724 void 725 auth_debug_send(void) 726 { 727 char *msg; 728 729 if (!auth_debug_init) 730 return; 731 while (buffer_len(&auth_debug)) { 732 msg = buffer_get_string(&auth_debug, NULL); 733 packet_send_debug("%s", msg); 734 free(msg); 735 } 736 } 737 738 void 739 auth_debug_reset(void) 740 { 741 if (auth_debug_init) 742 buffer_clear(&auth_debug); 743 else { 744 buffer_init(&auth_debug); 745 auth_debug_init = 1; 746 } 747 } 748 749 struct passwd * 750 fakepw(void) 751 { 752 static struct passwd fake; 753 static char nouser[] = "NOUSER"; 754 static char nonexist[] = "/nonexist"; 755 756 memset(&fake, 0, sizeof(fake)); 757 fake.pw_name = nouser; 758 fake.pw_passwd = __UNCONST( 759 "$2a$06$r3.juUaHZDlIbQaO2dS9FuYxL1W9M81R1Tc92PoSNmzvpEqLkLGrK"); 760 fake.pw_gecos = nouser; 761 fake.pw_uid = (uid_t)-1; 762 fake.pw_gid = (gid_t)-1; 763 fake.pw_class = __UNCONST(""); 764 fake.pw_dir = nonexist; 765 fake.pw_shell = nonexist; 766 767 return (&fake); 768 } 769