]> andersk Git - openssh.git/blame - openbsd-compat/port-aix.c
- (dtucker) [auth-passwd.c auth.h openbsd-compat/port-aix.c
[openssh.git] / openbsd-compat / port-aix.c
CommitLineData
0ba40daa 1/*
34a88012 2 *
3 * Copyright (c) 2001 Gert Doering. All rights reserved.
4 *
0ba40daa 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 */
90e70cfc 26#include "includes.h"
73d9dad3 27#include "ssh.h"
28#include "log.h"
29#include "servconf.h"
805dcf3a 30#include "canohost.h"
31#include "xmalloc.h"
f0b467ef 32#include "buffer.h"
90e70cfc 33
34#ifdef _AIX
35
36#include <uinfo.h>
2aa3a16c 37#include "port-aix.h"
90e70cfc 38
73d9dad3 39extern ServerOptions options;
f0b467ef 40extern Buffer loginmsg;
73d9dad3 41
d852ad8b 42# ifdef HAVE_SETAUTHDB
43static char old_registry[REGISTRY_SIZE] = "";
44# endif
45
90e70cfc 46/*
0ba40daa 47 * AIX has a "usrinfo" area where logname and other stuff is stored -
48 * a few applications actually use this and die if it's not set
49 *
50 * NOTE: TTY= should be set, but since no one uses it and it's hard to
51 * acquire due to privsep code. We will just drop support.
90e70cfc 52 */
53void
0ba40daa 54aix_usrinfo(struct passwd *pw)
90e70cfc 55{
90e70cfc 56 u_int i;
9901cb37 57 size_t len;
0ba40daa 58 char *cp;
90e70cfc 59
9901cb37 60 len = sizeof("LOGNAME= NAME= ") + (2 * strlen(pw->pw_name));
61 cp = xmalloc(len);
62
1e72a7e3 63 i = snprintf(cp, len, "LOGNAME=%s%cNAME=%s%c", pw->pw_name, '\0',
64 pw->pw_name, '\0');
90e70cfc 65 if (usrinfo(SETUINFO, cp, i) == -1)
66 fatal("Couldn't set usrinfo: %s", strerror(errno));
67 debug3("AIX/UsrInfo: set len %d", i);
9901cb37 68
90e70cfc 69 xfree(cp);
70}
71
f0b467ef 72# ifdef WITH_AIXAUTHENTICATE
bc7dfc06 73/*
74 * Remove embedded newlines in string (if any).
75 * Used before logging messages returned by AIX authentication functions
76 * so the message is logged on one line.
77 */
78void
79aix_remove_embedded_newlines(char *p)
80{
81 if (p == NULL)
82 return;
83
84 for (; *p; p++) {
85 if (*p == '\n')
86 *p = ' ';
87 }
88 /* Remove trailing whitespace */
89 if (*--p == ' ')
90 *p = '\0';
91}
f0b467ef 92
93/*
94 * Do authentication via AIX's authenticate routine. We loop until the
95 * reenter parameter is 0, but normally authenticate is called only once.
96 *
97 * Note: this function returns 1 on success, whereas AIX's authenticate()
98 * returns 0.
99 */
100int
cadfc759 101sys_auth_passwd(Authctxt *ctxt, const char *password)
f0b467ef 102{
cadfc759 103 char *authmsg = NULL, *host, *msg, *name = ctxt->pw->pw_name;
104 int authsuccess = 0, expired, reenter, result;
f0b467ef 105
106 do {
107 result = authenticate((char *)name, (char *)password, &reenter,
108 &authmsg);
109 aix_remove_embedded_newlines(authmsg);
110 debug3("AIX/authenticate result %d, msg %.100s", result,
111 authmsg);
112 } while (reenter);
113
114 if (result == 0) {
115 authsuccess = 1;
116
cadfc759 117 host = (char *)get_canonical_hostname(options.use_dns);
118
119 /*
120 * Record successful login. We don't have a pty yet, so just
121 * label the line as "ssh"
122 */
f0b467ef 123 aix_setauthdb(name);
124 if (loginsuccess((char *)name, (char *)host, "ssh", &msg) == 0) {
125 if (msg != NULL) {
126 debug("%s: msg %s", __func__, msg);
127 buffer_append(&loginmsg, msg, strlen(msg));
128 xfree(msg);
129 }
130 }
cadfc759 131
132 /*
133 * Check if the user's password is expired.
134 */
135 expired = passwdexpired(name, &msg);
136 if (msg && *msg) {
137 buffer_append(&loginmsg, msg, strlen(msg));
138 aix_remove_embedded_newlines(msg);
139 }
140 debug3("AIX/passwdexpired returned %d msg %.100s", expired, msg);
141
142 switch (expired) {
143 case 0: /* password not expired */
144 break;
145 case 1: /* expired, password change required */
146 ctxt->force_pwchange = 1;
147 disable_forwarding();
148 break;
149 default: /* user can't change(2) or other error (-1) */
150 logit("Password can't be changed for user %s: %.100s",
151 name, msg);
152 if (msg)
153 xfree(msg);
154 authsuccess = 0;
155 }
156
d852ad8b 157 aix_restoreauthdb();
f0b467ef 158 }
159
160 if (authmsg != NULL)
161 xfree(authmsg);
162
163 return authsuccess;
164}
bc7dfc06 165
f0b467ef 166# ifdef CUSTOM_FAILED_LOGIN
73d9dad3 167/*
168 * record_failed_login: generic "login failed" interface function
169 */
170void
171record_failed_login(const char *user, const char *ttyname)
172{
f0b467ef 173 char *hostname = (char *)get_canonical_hostname(options.use_dns);
9901cb37 174
2aa3a16c 175 if (geteuid() != 0)
176 return;
177
178 aix_setauthdb(user);
f0b467ef 179# ifdef AIX_LOGINFAILED_4ARG
f58c0e01 180 loginfailed((char *)user, hostname, (char *)ttyname, AUDIT_FAIL_AUTH);
f0b467ef 181# else
e351e493 182 loginfailed((char *)user, hostname, (char *)ttyname);
f0b467ef 183# endif
d852ad8b 184 aix_restoreauthdb();
73d9dad3 185}
f0b467ef 186# endif /* CUSTOM_FAILED_LOGIN */
2aa3a16c 187
188/*
189 * If we have setauthdb, retrieve the password registry for the user's
d852ad8b 190 * account then feed it to setauthdb. This will mean that subsequent AIX auth
191 * functions will only use the specified loadable module. If we don't have
192 * setauthdb this is a no-op.
2aa3a16c 193 */
194void
195aix_setauthdb(const char *user)
196{
197# ifdef HAVE_SETAUTHDB
d852ad8b 198 char *registry;
2aa3a16c 199
200 if (setuserdb(S_READ) == -1) {
201 debug3("%s: Could not open userdb to read", __func__);
202 return;
203 }
204
205 if (getuserattr((char *)user, S_REGISTRY, &registry, SEC_CHAR) == 0) {
d852ad8b 206 if (setauthdb(registry, old_registry) == 0)
207 debug3("AIX/setauthdb set registry '%s'", registry);
2aa3a16c 208 else
d852ad8b 209 debug3("AIX/setauthdb set registry '%s' failed: %s",
210 registry, strerror(errno));
2aa3a16c 211 } else
212 debug3("%s: Could not read S_REGISTRY for user: %s", __func__,
213 strerror(errno));
214 enduserdb();
f0b467ef 215# endif /* HAVE_SETAUTHDB */
2aa3a16c 216}
90e70cfc 217
d852ad8b 218/*
219 * Restore the user's registry settings from old_registry.
220 * Note that if the first aix_setauthdb fails, setauthdb("") is still safe
221 * (it restores the system default behaviour). If we don't have setauthdb,
222 * this is a no-op.
223 */
224void
225aix_restoreauthdb(void)
226{
227# ifdef HAVE_SETAUTHDB
228 if (setauthdb(old_registry, NULL) == 0)
229 debug3("%s: restoring old registry '%s'", __func__,
230 old_registry);
231 else
232 debug3("%s: failed to restore old registry %s", __func__,
233 old_registry);
234# endif /* HAVE_SETAUTHDB */
235}
236
f0b467ef 237# endif /* WITH_AIXAUTHENTICATE */
238
239#endif /* _AIX */
This page took 0.154889 seconds and 5 git commands to generate.