port-uw.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2005 The SCO Group. All rights reserved.
  3. * Copyright (c) 2005 Tim Rice. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "includes.h"
  26. #if defined(HAVE_LIBIAF) && !defined(HAVE_SECUREWARE)
  27. #include <sys/types.h>
  28. #ifdef HAVE_CRYPT_H
  29. # include <crypt.h>
  30. #endif
  31. #include <pwd.h>
  32. #include <stdarg.h>
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include "xmalloc.h"
  37. #include "packet.h"
  38. #include "auth-options.h"
  39. #include "log.h"
  40. #include "misc.h" /* servconf.h needs misc.h for struct ForwardOptions */
  41. #include "servconf.h"
  42. #include "hostfile.h"
  43. #include "auth.h"
  44. #include "ssh.h"
  45. #include "ssh_api.h"
  46. int nischeck(char *);
  47. int
  48. sys_auth_passwd(struct ssh *ssh, const char *password)
  49. {
  50. Authctxt *authctxt = ssh->authctxt;
  51. struct passwd *pw = authctxt->pw;
  52. char *salt;
  53. int result;
  54. /* Just use the supplied fake password if authctxt is invalid */
  55. char *pw_password = authctxt->valid ? shadow_pw(pw) : pw->pw_passwd;
  56. if (pw_password == NULL)
  57. return 0;
  58. /* Check for users with no password. */
  59. if (strcmp(pw_password, "") == 0 && strcmp(password, "") == 0)
  60. return (1);
  61. /* Encrypt the candidate password using the proper salt. */
  62. salt = (pw_password[0] && pw_password[1]) ? pw_password : "xx";
  63. /*
  64. * Authentication is accepted if the encrypted passwords
  65. * are identical.
  66. */
  67. #ifdef UNIXWARE_LONG_PASSWORDS
  68. if (!nischeck(pw->pw_name)) {
  69. result = ((strcmp(bigcrypt(password, salt), pw_password) == 0)
  70. || (strcmp(osr5bigcrypt(password, salt), pw_password) == 0));
  71. }
  72. else
  73. #endif /* UNIXWARE_LONG_PASSWORDS */
  74. result = (strcmp(xcrypt(password, salt), pw_password) == 0);
  75. #ifdef USE_LIBIAF
  76. if (authctxt->valid)
  77. free(pw_password);
  78. #endif
  79. return(result);
  80. }
  81. #ifdef UNIXWARE_LONG_PASSWORDS
  82. int
  83. nischeck(char *namep)
  84. {
  85. char password_file[] = "/etc/passwd";
  86. FILE *fd;
  87. struct passwd *ent = NULL;
  88. if ((fd = fopen (password_file, "r")) == NULL) {
  89. /*
  90. * If the passwd file has disappeared we are in a bad state.
  91. * However, returning 0 will send us back through the
  92. * authentication scheme that has checked the ia database for
  93. * passwords earlier.
  94. */
  95. return(0);
  96. }
  97. /*
  98. * fgetpwent() only reads from password file, so we know for certain
  99. * that the user is local.
  100. */
  101. while (ent = fgetpwent(fd)) {
  102. if (strcmp (ent->pw_name, namep) == 0) {
  103. /* Local user */
  104. fclose (fd);
  105. return(0);
  106. }
  107. }
  108. fclose (fd);
  109. return (1);
  110. }
  111. #endif /* UNIXWARE_LONG_PASSWORDS */
  112. /*
  113. NOTE: ia_get_logpwd() allocates memory for arg 2
  114. functions that call shadow_pw() will need to free
  115. */
  116. #ifdef USE_LIBIAF
  117. char *
  118. get_iaf_password(struct passwd *pw)
  119. {
  120. char *pw_password = NULL;
  121. uinfo_t uinfo;
  122. if (!ia_openinfo(pw->pw_name,&uinfo)) {
  123. ia_get_logpwd(uinfo, &pw_password);
  124. if (pw_password == NULL)
  125. fatal("ia_get_logpwd: Unable to get the shadow passwd");
  126. ia_closeinfo(uinfo);
  127. return pw_password;
  128. }
  129. else
  130. fatal("ia_openinfo: Unable to open the shadow passwd file");
  131. }
  132. #endif /* USE_LIBIAF */
  133. #endif /* HAVE_LIBIAF and not HAVE_SECUREWARE */