pw_nis.c revision 21673
1243791Sdim/*- 2243791Sdim * Copyright (C) 1996 3243791Sdim * David L. Nugent. All rights reserved. 4243791Sdim * 5243791Sdim * Redistribution and use in source and binary forms, with or without 6243791Sdim * modification, are permitted provided that the following conditions 7243791Sdim * are met: 8243791Sdim * 1. Redistributions of source code must retain the above copyright 9243791Sdim * notice, this list of conditions and the following disclaimer. 10243791Sdim * 2. Redistributions in binary form must reproduce the above copyright 11243791Sdim * notice, this list of conditions and the following disclaimer in the 12243791Sdim * documentation and/or other materials provided with the distribution. 13243791Sdim * 14243791Sdim * THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND 15243791Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16243791Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17252723Sdim * ARE DISCLAIMED. IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE 18243791Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19252723Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20252723Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21252723Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22243791Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23252723Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24243791Sdim * SUCH DAMAGE. 25252723Sdim * 26252723Sdim * $FreeBSD: head/usr.sbin/pw/pw_nis.c 21673 1997-01-14 07:20:47Z jkh $ 27252723Sdim */ 28252723Sdim 29252723Sdim#include <stdio.h> 30243791Sdim#include <stdlib.h> 31243791Sdim#include <string.h> 32243791Sdim#include <sys/types.h> 33243791Sdim 34243791Sdim#include "pwupd.h" 35243791Sdim#include "pw.h" 36243791Sdim 37243791Sdimstatic int 38243791Sdimpw_nisupdate(const char * path, struct passwd * pwd, char const * user, int mode) 39243791Sdim{ 40243791Sdim char pfx[32]; 41243791Sdim char pwbuf[PWBUFSZ]; 42243791Sdim int l = sprintf(pfx, "%s:", user); 43243791Sdim 44243791Sdim /* 45243791Sdim * Update the passwd file first 46243791Sdim */ 47243791Sdim if (pwd == NULL) 48243791Sdim *pwbuf = '\0'; 49243791Sdim else 50243791Sdim fmtpwentry(pwbuf, pwd, PWF_MASTER); 51243791Sdim return fileupdate(path, 0600, pwbuf, pfx, l, mode) != 0; 52243791Sdim} 53243791Sdim 54243791Sdimint 55243791Sdimaddnispwent(const char *path, struct passwd * pwd) 56243791Sdim{ 57243791Sdim return pw_nisupdate(path, pwd, pwd->pw_name, UPD_CREATE); 58243791Sdim} 59243791Sdim 60243791Sdimint 61243791Sdimchgnispwent(const char *path, char const * login, struct passwd * pwd) 62243791Sdim{ 63243791Sdim return pw_nisupdate(path, pwd, login, UPD_REPLACE); 64243791Sdim} 65243791Sdim 66243791Sdimint 67243791Sdimdelnispwent(const char *path, const char *login) 68243791Sdim{ 69243791Sdim return pw_nisupdate(path, NULL, login, UPD_DELETE); 70243791Sdim} 71243791Sdim