623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * CDDL HEADER START
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * The contents of this file are subject to the terms of the
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * Common Development and Distribution License (the "License").
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * You may not use this file except in compliance with the License.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * See the License for the specific language governing permissions
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * and limitations under the License.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * When distributing Covered Code, include this CDDL HEADER in each
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * If applicable, add the following below this CDDL HEADER, with the
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * fields enclosed by brackets "[]" replaced with your own identifying
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * information: Portions Copyright [yyyy] [name of copyright owner]
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * CDDL HEADER END
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * Use is subject to license terms.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * This file has all of the PAM related code for sys-suspend. It is
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * part of it's own file, as these could be part of some bigger item
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * that can handle generic PAM facilities (certainly the getinput()
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * function could be in a common library). However, as that does not
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * yet exist, we replicate it here so we can get the job done.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel#define __EXTENSIONS__ /* to expose flockfile and friends in stdio.h */
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishelstatic int ctl_c; /* was the conversation interrupted? */
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel/* ARGSUSED 1 */
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * getinput -- read user input from stdin abort on ^C
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * Entry noecho == TRUE, don't echo input.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * Exit User's input.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * If interrupted, send SIGINT to caller for processing.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishelstatic char *
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel void (*sig)(int);
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel tty.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel /* go to end, but don't overflow PAM_MAX_RESP_SIZE */
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel while (ctl_c == 0 &&
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel c != '\r' &&
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel input[i++] = (char)c;
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * Service modules don't clean up responses if an error is returned.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * Free responses here.
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel for (i = 0; i < num_msg; i++, r++) {
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel /* clear before freeing -- may be a password */
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel/* ARGSUSED */
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishelpam_tty_conv(int num_msg, struct pam_message **mess,
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel struct pam_response *r = calloc(num_msg, sizeof (struct pam_response));
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel (void) fprintf(stderr, "too many messages %d >= %d\n",
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel /* Talk it out */
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel for (i = 0; i < num_msg; i++) {
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel /* bad message from service module */
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel (void) fprintf(stderr, "message[%d]: %d/NULL\n",
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * fix up final newline:
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * removed for prompts
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel * added back for messages
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel /*FALLTHROUGH*/
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel (void) fprintf(stderr, "message[%d]: unknown type "
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel "%d/val=\"%s\"\n",
623ec8b0965ca16c95dab78c0bd2af81733a0253Randy Fishel /* error, service module won't clean up */