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.

96 lines
2.6KB

  1. /*
  2. * Copyright (c) 2001 Reza Arbab <arbab@austin.ibm.com>
  3. * Copyright (c) 2003 Oswald Buddenhagen <ossi@kde.org>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public
  16. * License along with this program; if not, write to the Free
  17. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #include "kcheckpass.h"
  21. #ifdef HAVE_AIX_AUTH
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <errno.h>
  26. /*
  27. * The AIX builtin authenticate() uses whichever method the system
  28. * has been configured for. (/etc/passwd, DCE, etc.)
  29. */
  30. int authenticate(const char *, const char *, int *, char **);
  31. AuthReturn Authenticate(const char *method,
  32. const char *login, char *(*conv) (ConvRequest, const char *))
  33. {
  34. int result;
  35. int reenter; /* Tells if authenticate is done processing or not. */
  36. char *passwd;
  37. char *msg; /* Contains a prompt message or failure reason. */
  38. if (!strcmp(method, "classic")) {
  39. if (!(passwd = conv(ConvGetHidden, 0)))
  40. return AuthAbort;
  41. if ((result = authenticate(login, passwd, &reenter, &msg))) {
  42. if (msg) {
  43. conv(ConvPutError, msg);
  44. free(msg);
  45. }
  46. dispose(passwd);
  47. return AuthBad;
  48. }
  49. if (reenter) {
  50. char buf[256];
  51. snprintf(buf, sizeof(buf), "More authentication data requested: %s\n", msg);
  52. conv(ConvPutError, buf);
  53. free(msg);
  54. dispose(passwd);
  55. return result == ENOENT || result == ESAD ? AuthBad : AuthError;
  56. }
  57. dispose(passwd);
  58. return AuthOk;
  59. } else if (!strcmp(method, "generic")) {
  60. for (passwd = 0;;) {
  61. if ((result = authenticate(login, passwd, &reenter, &msg))) {
  62. if (msg) {
  63. conv(ConvPutError, msg);
  64. free(msg);
  65. }
  66. if (passwd)
  67. dispose(passwd);
  68. return result == ENOENT || result == ESAD ? AuthBad : AuthError;
  69. }
  70. if (passwd)
  71. dispose(passwd);
  72. if (!reenter)
  73. break;
  74. passwd = conv(ConvGetHidden, msg);
  75. free(msg);
  76. if (!passwd)
  77. return AuthAbort;
  78. }
  79. return AuthOk;
  80. } else
  81. return AuthError;
  82. }
  83. #endif