1 /* $OpenBSD: login_chpass.c,v 1.22 2024/09/22 04:19:22 jsg Exp $ */
2
3 /*-
4 * Copyright (c) 1995,1996 Berkeley Software Design, Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Berkeley Software Design,
17 * Inc.
18 * 4. The name of Berkeley Software Design, Inc. may not be used to endorse
19 * or promote products derived from this software without specific prior
20 * written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN, INC. BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * BSDI $From: login_chpass.c,v 1.3 1996/08/21 21:01:48 prb Exp $
35 */
36
37 #include <sys/resource.h>
38
39 #include <err.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <syslog.h>
43 #include <unistd.h>
44
45 #define _PATH_LOGIN_LCHPASS "/usr/libexec/auth/login_lchpass"
46
47 void local_chpass(char **);
48
49 int
main(int argc,char * argv[])50 main(int argc, char *argv[])
51 {
52 struct rlimit rl;
53 int c;
54
55 rl.rlim_cur = 0;
56 rl.rlim_max = 0;
57 (void)setrlimit(RLIMIT_CORE, &rl);
58
59 (void)setpriority(PRIO_PROCESS, 0, 0);
60
61 if (pledge("stdio exec", NULL) == -1)
62 err(1, "pledge");
63
64 openlog("login", LOG_ODELAY, LOG_AUTH);
65
66 while ((c = getopt(argc, argv, "s:v:")) != -1)
67 switch (c) {
68 case 'v':
69 break;
70 case 's': /* service */
71 if (strcmp(optarg, "login") != 0) {
72 syslog(LOG_ERR, "%s: invalid service", optarg);
73 exit(1);
74 }
75 break;
76 default:
77 syslog(LOG_ERR, "usage error");
78 exit(1);
79 }
80
81 switch (argc - optind) {
82 case 2:
83 /* class is not used */
84 case 1:
85 break;
86 default:
87 syslog(LOG_ERR, "usage error");
88 exit(1);
89 }
90
91 local_chpass(argv);
92 /* NOTREACHED */
93 exit(0);
94 }
95
96 void
local_chpass(char * argv[])97 local_chpass(char *argv[])
98 {
99
100 /* login_lchpass doesn't check instance so don't bother restoring it */
101 argv[0] = strrchr(_PATH_LOGIN_LCHPASS, '/') + 1;
102 execv(_PATH_LOGIN_LCHPASS, argv);
103 syslog(LOG_ERR, "%s: %m", _PATH_LOGIN_LCHPASS);
104 exit(1);
105 }
106