]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libutil/login.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libutil / login.c
1 /*-
2  * Copyright (c) 1988, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
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  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34 #if defined(LIBC_SCCS) && !defined(lint)
35 #if 0
36 static char sccsid[] = "@(#)login.c     8.1 (Berkeley) 6/4/93";
37 #endif
38 #endif /* LIBC_SCCS and not lint */
39
40 #include <sys/types.h>
41
42 #include <fcntl.h>
43 #include <libutil.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <ttyent.h>
47 #include <unistd.h>
48 #include <utmp.h>
49
50 void
51 login(struct utmp *ut)
52 {
53         struct ttyent *ty;
54         int fd;
55         int tty;
56
57         setttyent();
58         for (tty = 1; (ty = getttyent()) != NULL; ++tty)
59                 if (strcmp(ty->ty_name, ut->ut_line) == 0)
60                         break;
61         endttyent();
62         if (tty > 0 && (fd = open(_PATH_UTMP, O_WRONLY|O_CREAT, 0644)) >= 0) {
63                 (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), L_SET);
64                 (void)write(fd, ut, sizeof(struct utmp));
65                 (void)close(fd);
66         }
67         if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
68                 (void)write(fd, ut, sizeof(struct utmp));
69                 (void)close(fd);
70         }
71 }