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