4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
39 #pragma ident "%Z%%M% %I% %E% SMI"
45 #include <sys/types.h>
50 #include <security/pam_appl.h>
55 extern char *lastname();
58 * account - create a utmpx record for service
66 struct utmpx utmpx
; /* prototype utmpx entry */
67 struct utmpx
*up
= &utmpx
; /* and a pointer to it */
69 (void) memset(up
, '\0', sizeof (utmpx
));
71 (void) strncpy(&up
->ut_user
[1], Tag
, sizeof (up
->ut_user
)-1);
72 (void) strncpy(up
->ut_line
, lastname(line
), sizeof (up
->ut_line
));
73 up
->ut_pid
= getpid();
74 up
->ut_type
= USER_PROCESS
;
77 up
->ut_id
[2] = SC_WILDC
;
78 up
->ut_id
[3] = SC_WILDC
;
79 up
->ut_exit
.e_termination
= 0;
80 up
->ut_exit
.e_exit
= 0;
81 (void) time(&up
->ut_tv
.tv_sec
);
82 if (makeutx(up
) == NULL
) {
83 log("makeutx for pid %d failed", up
->ut_pid
);
90 * checkut_line - check if a login is active on the requested device
93 checkut_line(char *line
)
96 char buf
[33], ttyn
[33];
98 pid_t ownpid
= getpid();
100 (void) strncpy(buf
, lastname(line
), sizeof (u
->ut_line
));
101 buf
[sizeof (u
->ut_line
)] = '\0';
104 while ((u
= getutxent()) != NULL
) {
105 if (u
->ut_pid
== ownpid
) {
106 if (u
->ut_type
== USER_PROCESS
) {
107 strncpy(ttyn
, u
->ut_line
, sizeof (u
->ut_line
));
108 ttyn
[sizeof (u
->ut_line
)] = '\0';
109 if (strcmp(buf
, ttyn
) == 0) {
130 char user
[33], ttyn
[33], rhost
[258];
133 while (up
= getutxent()) {
134 if (up
->ut_pid
== pid
) {
135 if (up
->ut_type
== DEAD_PROCESS
) {
136 /* Cleaned up elsewhere. */
140 strncpy(user
, up
->ut_user
, sizeof (up
->ut_user
));
141 user
[sizeof (up
->ut_user
)] = '\0';
142 strncpy(ttyn
, up
->ut_line
, sizeof (up
->ut_line
));
143 ttyn
[sizeof (up
->ut_line
)] = '\0';
144 strncpy(rhost
, up
->ut_host
, sizeof (up
->ut_host
));
145 rhost
[sizeof (up
->ut_host
)] = '\0';
147 if (pam_start("ttymon", user
, NULL
, &pamh
)
149 (void) pam_set_item(pamh
, PAM_TTY
, ttyn
);
150 (void) pam_set_item(pamh
, PAM_RHOST
, rhost
);
151 (void) pam_close_session(pamh
, 0);
152 (void) pam_end(pamh
, PAM_SUCCESS
);
156 up
->ut_type
= DEAD_PROCESS
;
157 up
->ut_exit
.e_termination
= WTERMSIG(status
);
158 up
->ut_exit
.e_exit
= WEXITSTATUS(status
);
159 (void) time(&up
->ut_tv
.tv_sec
);
161 if (modutx(up
) == NULL
) {
163 * Since modutx failed we'll
164 * write out the new entry
167 (void) pututxline(up
);
168 updwtmpx("wtmpx", up
);
177 * getty_account - This is a copy of old getty account routine.
178 * - This is only called if ttymon is invoked as getty.
179 * - It tries to find its own INIT_PROCESS entry in utmpx
180 * - and change it to LOGIN_PROCESS
192 while ((u
= getutxent()) != NULL
) {
194 if (u
->ut_type
== INIT_PROCESS
&& u
->ut_pid
== ownpid
) {
195 (void) strncpy(u
->ut_line
, lastname(line
),
196 sizeof (u
->ut_line
));
197 (void) strncpy(u
->ut_user
, "LOGIN",
198 sizeof (u
->ut_user
));
199 u
->ut_type
= LOGIN_PROCESS
;
201 /* Write out the updated entry. */
202 (void) pututxline(u
);
207 /* create wtmpx entry also */
209 updwtmpx("/etc/wtmpx", u
);