crash fix from Anthony Bryant
[kdebase.git] / workspace / kcheckpass / checkpass_aix.c
blob8f06cfe672c2d9efef30d0a8080578503a615e15
1 /*
2 * Copyright (c) 2001 Reza Arbab <arbab@austin.ibm.com>
3 * Copyright (c) 2003 Oswald Buddenhagen <ossi@kde.org>
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.
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.
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.
21 #include "kcheckpass.h"
23 #ifdef HAVE_AIX_AUTH
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <errno.h>
29 /*
30 * The AIX builtin authenticate() uses whichever method the system
31 * has been configured for. (/etc/passwd, DCE, etc.)
33 int authenticate(const char *, const char *, int *, char **);
35 AuthReturn Authenticate(const char *method,
36 const char *login, char *(*conv) (ConvRequest, const char *))
38 int result;
39 int reenter; /* Tells if authenticate is done processing or not. */
40 char *passwd;
41 char *msg; /* Contains a prompt message or failure reason. */
43 if (!strcmp(method, "classic")) {
45 if (!(passwd = conv(ConvGetHidden, 0)))
46 return AuthAbort;
48 if ((result = authenticate(login, passwd, &reenter, &msg))) {
49 if (msg) {
50 conv(ConvPutError, msg);
51 free(msg);
53 dispose(passwd);
54 return AuthBad;
56 if (reenter) {
57 char buf[256];
58 snprintf(buf, sizeof(buf), "More authentication data requested: %s\n", msg);
59 conv(ConvPutError, buf);
60 free(msg);
61 dispose(passwd);
62 return result == ENOENT || result == ESAD ? AuthBad : AuthError;
64 dispose(passwd);
65 return AuthOk;
67 } else if (!strcmp(method, "generic")) {
69 for (passwd = 0;;) {
70 if ((result = authenticate(login, passwd, &reenter, &msg))) {
71 if (msg) {
72 conv(ConvPutError, msg);
73 free(msg);
75 if (passwd)
76 dispose(passwd);
77 return result == ENOENT || result == ESAD ? AuthBad : AuthError;
79 if (passwd)
80 dispose(passwd);
81 if (!reenter)
82 break;
83 passwd = conv(ConvGetHidden, msg);
84 free(msg);
85 if (!passwd)
86 return AuthAbort;
88 return AuthOk;
90 } else
91 return AuthError;
95 #endif