TDE base libraries and programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.5KB

  1. /*
  2. * Copyright (C) 1998 Christian Esken <esken@kde.org>
  3. * Copyright (C) 2003 Oswald Buddenhagen <ossi@kde.org>
  4. *
  5. * This is a modified version of checkpass_shadow.cpp
  6. *
  7. * Modifications made by Thorsten Kukuk <kukuk@suse.de>
  8. * Mathias Kettner <kettner@suse.de>
  9. *
  10. * ------------------------------------------------------------
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public
  14. * License as published by the Free Software Foundation; either
  15. * version 2 of the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public
  23. * License along with this program; if not, write to the Free
  24. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  25. */
  26. #include "kcheckpass.h"
  27. /*******************************************************************
  28. * This is the authentication code for Shadow-Passwords
  29. *******************************************************************/
  30. #ifdef HAVE_SHADOW
  31. #include <string.h>
  32. #include <stdlib.h>
  33. #include <pwd.h>
  34. #ifndef __hpux
  35. #include <shadow.h>
  36. #endif
  37. AuthReturn Authenticate(const char *method,
  38. const char *login, char *(*conv) (ConvRequest, const char *))
  39. {
  40. char *typed_in_password;
  41. char *crpt_passwd;
  42. char *password;
  43. struct passwd *pw;
  44. struct spwd *spw;
  45. if (strcmp(method, "classic"))
  46. return AuthError;
  47. if (!(pw = getpwnam(login)))
  48. return AuthAbort;
  49. spw = getspnam(login);
  50. password = spw ? spw->sp_pwdp : pw->pw_passwd;
  51. if (!*password)
  52. return AuthOk;
  53. if (!(typed_in_password = conv(ConvGetHidden, 0)))
  54. return AuthAbort;
  55. #if defined( __linux__ ) && defined( HAVE_PW_ENCRYPT )
  56. crpt_passwd = pw_encrypt(typed_in_password, password); /* (1) */
  57. #else
  58. crpt_passwd = crypt(typed_in_password, password);
  59. #endif
  60. if (!strcmp(password, crpt_passwd )) {
  61. dispose(typed_in_password);
  62. return AuthOk; /* Success */
  63. }
  64. dispose(typed_in_password);
  65. return AuthBad; /* Password wrong or account locked */
  66. }
  67. /*
  68. (1) Deprecated - long passwords have known weaknesses. Also,
  69. pw_encrypt is non-standard (requires libshadow.a) while
  70. everything else you need to support shadow passwords is in
  71. the standard (ELF) libc.
  72. */
  73. #endif