~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kcheckpass/checkpass_aix.c

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
21
#include "kcheckpass.h"
 
22
 
 
23
#ifdef HAVE_AIX_AUTH
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
#include <string.h>
 
27
#include <errno.h>
 
28
 
 
29
/* 
 
30
 * The AIX builtin authenticate() uses whichever method the system 
 
31
 * has been configured for.  (/etc/passwd, DCE, etc.)
 
32
 */
 
33
int authenticate(const char *, const char *, int *, char **);
 
34
 
 
35
AuthReturn Authenticate(const char *method,
 
36
        const char *login, char *(*conv) (ConvRequest, const char *))
 
37
{
 
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.     */
 
42
 
 
43
  if (!strcmp(method, "classic")) {
 
44
 
 
45
    if (!(passwd = conv(ConvGetHidden, 0)))
 
46
      return AuthAbort;
 
47
 
 
48
    if ((result = authenticate(login, passwd, &reenter, &msg))) {
 
49
      if (msg) {
 
50
        conv(ConvPutError, msg);
 
51
        free(msg);
 
52
      }
 
53
      dispose(passwd);
 
54
      return AuthBad;
 
55
    }
 
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;
 
63
    }
 
64
    dispose(passwd);
 
65
    return AuthOk;
 
66
 
 
67
  } else if (!strcmp(method, "generic")) {
 
68
 
 
69
    for (passwd = 0;;) {
 
70
      if ((result = authenticate(login, passwd, &reenter, &msg))) {
 
71
        if (msg) {
 
72
          conv(ConvPutError, msg);
 
73
          free(msg);
 
74
        }
 
75
        if (passwd)
 
76
          dispose(passwd);
 
77
        return result == ENOENT || result == ESAD ? AuthBad : AuthError;
 
78
      }
 
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;
 
87
    }
 
88
    return AuthOk;
 
89
 
 
90
  } else
 
91
    return AuthError;
 
92
 
 
93
}
 
94
 
 
95
#endif