Skip to content

Commit 8ae2c37

Browse files
sswamy48millert
authored andcommitted
Use aix extended authentication APIs.
1 parent 02ff3af commit 8ae2c37

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

plugins/sudoers/auth/aix_auth.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,23 +228,48 @@ int
228228
sudo_aix_verify(const struct sudoers_context *ctx, struct passwd *pw,
229229
const char *prompt, sudo_auth *auth, struct sudo_conv_callback *callback)
230230
{
231-
char *pass, *message = NULL;
232-
int result = 1, reenter = 0;
231+
char *pass, *message = NULL, *restrict_msg = NULL;
232+
int result = 1, reenter = 0, restrict_result = -1, pwdexp_msg = 0;
233233
int ret = AUTH_SUCCESS;
234+
void *login_state = NULL;
234235
debug_decl(sudo_aix_verify, SUDOERS_DEBUG_AUTH);
235236

236237
if (IS_NONINTERACTIVE(auth))
237238
debug_return_int(AUTH_NONINTERACTIVE);
238239

240+
/* Use newer APIs to propogate the state information. */
241+
restrict_result = loginrestrictionsx(pw->pw_name, 0, NULL,
242+
&restrict_msg, &login_state);
243+
if (restrict_result != 0)
244+
{
245+
if (restrict_msg != NULL && restrict_msg[0] != '\0')
246+
{
247+
struct sudo_conv_message msg;
248+
struct sudo_conv_reply repl;
249+
250+
memset(&msg, 0, sizeof(msg));
251+
msg.msg_type = SUDO_CONV_ERROR_MSG;
252+
msg.msg = restrict_msg;
253+
memset(&repl, 0, sizeof(repl));
254+
sudo_conv(1, &msg, &repl, NULL);
255+
free(restrict_msg);
256+
restrict_msg = NULL;
257+
}
258+
sudo_warn("loginrestrictionsx");
259+
debug_return_int(AUTH_ERROR);
260+
}
261+
239262
do {
240263
pass = auth_getpass(prompt, SUDO_CONV_PROMPT_ECHO_OFF, callback);
241264
if (pass == NULL)
242265
break;
243266
free(message);
244267
message = NULL;
245-
result = authenticate(pw->pw_name, pass, &reenter, &message);
268+
result = authenticatex(pw->pw_name, pass, &reenter, &message, &login_state);
246269
freezero(pass, strlen(pass));
247270
prompt = message;
271+
if (!reenter && !result && message)
272+
sudo_printf(SUDO_CONV_ERROR_MSG, "%s ", message);
248273
} while (reenter);
249274

250275
if (result != 0) {
@@ -259,8 +284,9 @@ sudo_aix_verify(const struct sudoers_context *ctx, struct passwd *pw,
259284

260285
/* Check if password expired and allow user to change it if possible. */
261286
if (ret == AUTH_SUCCESS) {
262-
result = passwdexpired(pw->pw_name, &message);
287+
result = passwdexpiredx(pw->pw_name, &message, &login_state);
263288
if (message != NULL && message[0] != '\0') {
289+
pwdexp_msg = 1;
264290
int msg_type = SUDO_CONV_PREFER_TTY;
265291
msg_type |= result ? SUDO_CONV_ERROR_MSG : SUDO_CONV_INFO_MSG,
266292
sudo_printf(msg_type, "%s", message);
@@ -279,12 +305,15 @@ sudo_aix_verify(const struct sudoers_context *ctx, struct passwd *pw,
279305
}
280306
break;
281307
case 2:
308+
case 3:
282309
/* password expired, only admin can change it */
310+
if (!pwdexp_msg)
311+
sudo_printf(SUDO_CONV_ERROR_MSG, "Your password expired, only admin can change it.\n");
283312
ret = AUTH_ERROR;
284313
break;
285314
default:
286315
/* error (-1) */
287-
sudo_warn("passwdexpired");
316+
sudo_warn("passwdexpiredx");
288317
ret = AUTH_ERROR;
289318
break;
290319
}

0 commit comments

Comments
 (0)