140685Snsouch/*- 240685Snsouch * Copyright (C) 1996 340685Snsouch * David L. Nugent. All rights reserved. 440685Snsouch * 540685Snsouch * Redistribution and use in source and binary forms, with or without 640685Snsouch * modification, are permitted provided that the following conditions 740685Snsouch * are met: 840685Snsouch * 1. Redistributions of source code must retain the above copyright 940685Snsouch * notice, this list of conditions and the following disclaimer. 1040685Snsouch * 2. Redistributions in binary form must reproduce the above copyright 1140685Snsouch * notice, this list of conditions and the following disclaimer in the 1240685Snsouch * documentation and/or other materials provided with the distribution. 1340685Snsouch * 1440685Snsouch * THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND 1540685Snsouch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1640685Snsouch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1740685Snsouch * ARE DISCLAIMED. IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE 1840685Snsouch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1940685Snsouch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2040685Snsouch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2140685Snsouch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2240685Snsouch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2340685Snsouch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2440685Snsouch * SUCH DAMAGE. 2550476Speter */ 2640685Snsouch 2740685Snsouch#ifndef lint 28203692Sgavinstatic const char rcsid[] = 2979538Sru "$FreeBSD$"; 3040685Snsouch#endif /* not lint */ 3140685Snsouch 3275670Sru#include <stdio.h> 3340685Snsouch#include <stdlib.h> 3484877Syokota#include <string.h> 3540685Snsouch#include <sys/types.h> 3684877Syokota 3784877Syokota#include "pw.h" 3884877Syokota 3984877Syokotastatic int 4084877Syokotapw_nisupdate(const char * path, struct passwd * pwd, char const * user, int mode) 4184877Syokota{ 4240685Snsouch char pfx[32]; 4356468Sasmodai char pwbuf[PWBUFSZ]; 4440685Snsouch int l = sprintf(pfx, "%s:", user); 4540685Snsouch 4640685Snsouch /* 4740685Snsouch * Update the passwd file first 4840685Snsouch */ 4940685Snsouch if (pwd == NULL) 5040685Snsouch *pwbuf = '\0'; 5140685Snsouch else 5279727Sschweikh fmtpwentry(pwbuf, pwd, PWF_MASTER); 5357731Ssheldonh return fileupdate(path, 0600, pwbuf, pfx, l, mode) != 0; 5479727Sschweikh} 5557731Ssheldonh 5657731Ssheldonhint 5757731Ssheldonhaddnispwent(const char *path, struct passwd * pwd) 5857731Ssheldonh{ 5940685Snsouch return pw_nisupdate(path, pwd, pwd->pw_name, UPD_CREATE); 6040685Snsouch} 6140685Snsouch 6240685Snsouchint 6340685Snsouchchgnispwent(const char *path, char const * login, struct passwd * pwd) 6440685Snsouch{ 6540685Snsouch return pw_nisupdate(path, pwd, login, UPD_REPLACE); 6640685Snsouch} 6740685Snsouch 6840685Snsouchint 6949831Smppdelnispwent(const char *path, const char *login) 7040685Snsouch{ 7140685Snsouch return pw_nisupdate(path, NULL, login, UPD_DELETE); 7240685Snsouch} 73