121330Sdavidn/*- 221330Sdavidn * Copyright (C) 1996 321330Sdavidn * David L. Nugent. All rights reserved. 421330Sdavidn * 521330Sdavidn * Redistribution and use in source and binary forms, with or without 621330Sdavidn * modification, are permitted provided that the following conditions 721330Sdavidn * are met: 821330Sdavidn * 1. Redistributions of source code must retain the above copyright 921330Sdavidn * notice, this list of conditions and the following disclaimer. 1021330Sdavidn * 2. Redistributions in binary form must reproduce the above copyright 1121330Sdavidn * notice, this list of conditions and the following disclaimer in the 1221330Sdavidn * documentation and/or other materials provided with the distribution. 1321330Sdavidn * 1421330Sdavidn * THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND 1521330Sdavidn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1621330Sdavidn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1721330Sdavidn * ARE DISCLAIMED. IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE 1821330Sdavidn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1921330Sdavidn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2021330Sdavidn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2121330Sdavidn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2221330Sdavidn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2321330Sdavidn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2421330Sdavidn * SUCH DAMAGE. 2521330Sdavidn */ 2621330Sdavidn 2730259Scharnier#ifndef lint 2830259Scharnierstatic const char rcsid[] = 2950479Speter "$FreeBSD$"; 3030259Scharnier#endif /* not lint */ 3130259Scharnier 3221330Sdavidn#include <stdio.h> 3321330Sdavidn#include <stdlib.h> 3421330Sdavidn#include <string.h> 3521330Sdavidn#include <sys/types.h> 3621330Sdavidn 3721330Sdavidn#include "pw.h" 3821330Sdavidn 3921330Sdavidnstatic int 4021330Sdavidnpw_nisupdate(const char * path, struct passwd * pwd, char const * user, int mode) 4121330Sdavidn{ 4221330Sdavidn char pfx[32]; 4321330Sdavidn char pwbuf[PWBUFSZ]; 4421330Sdavidn int l = sprintf(pfx, "%s:", user); 4521330Sdavidn 4621330Sdavidn /* 4721330Sdavidn * Update the passwd file first 4821330Sdavidn */ 4921330Sdavidn if (pwd == NULL) 5021330Sdavidn *pwbuf = '\0'; 5121330Sdavidn else 5221330Sdavidn fmtpwentry(pwbuf, pwd, PWF_MASTER); 5321330Sdavidn return fileupdate(path, 0600, pwbuf, pfx, l, mode) != 0; 5421330Sdavidn} 5521330Sdavidn 5621330Sdavidnint 5721330Sdavidnaddnispwent(const char *path, struct passwd * pwd) 5821330Sdavidn{ 5921330Sdavidn return pw_nisupdate(path, pwd, pwd->pw_name, UPD_CREATE); 6021330Sdavidn} 6121330Sdavidn 6221330Sdavidnint 6321330Sdavidnchgnispwent(const char *path, char const * login, struct passwd * pwd) 6421330Sdavidn{ 6521330Sdavidn return pw_nisupdate(path, pwd, login, UPD_REPLACE); 6621330Sdavidn} 6721330Sdavidn 6821330Sdavidnint 6921330Sdavidndelnispwent(const char *path, const char *login) 7021330Sdavidn{ 7121330Sdavidn return pw_nisupdate(path, NULL, login, UPD_DELETE); 7221330Sdavidn} 73