1f1d684faSDavid Nugent /*- 2f1d684faSDavid Nugent * Copyright (C) 1996 3f1d684faSDavid Nugent * David L. Nugent. All rights reserved. 4f1d684faSDavid Nugent * 5f1d684faSDavid Nugent * Redistribution and use in source and binary forms, with or without 6f1d684faSDavid Nugent * modification, are permitted provided that the following conditions 7f1d684faSDavid Nugent * are met: 8f1d684faSDavid Nugent * 1. Redistributions of source code must retain the above copyright 9f1d684faSDavid Nugent * notice, this list of conditions and the following disclaimer. 10f1d684faSDavid Nugent * 2. Redistributions in binary form must reproduce the above copyright 11f1d684faSDavid Nugent * notice, this list of conditions and the following disclaimer in the 12f1d684faSDavid Nugent * documentation and/or other materials provided with the distribution. 13f1d684faSDavid Nugent * 14f1d684faSDavid Nugent * THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND 15f1d684faSDavid Nugent * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16f1d684faSDavid Nugent * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17f1d684faSDavid Nugent * ARE DISCLAIMED. IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE 18f1d684faSDavid Nugent * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19f1d684faSDavid Nugent * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20f1d684faSDavid Nugent * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21f1d684faSDavid Nugent * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22f1d684faSDavid Nugent * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23f1d684faSDavid Nugent * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24f1d684faSDavid Nugent * SUCH DAMAGE. 25f1d684faSDavid Nugent * 26f1d684faSDavid Nugent * $Id$ 27f1d684faSDavid Nugent */ 28f1d684faSDavid Nugent 29f1d684faSDavid Nugent #include <stdio.h> 30f1d684faSDavid Nugent #include <stdlib.h> 31f1d684faSDavid Nugent #include <string.h> 32f1d684faSDavid Nugent #include <sys/types.h> 33f1d684faSDavid Nugent 34f1d684faSDavid Nugent #include "pwupd.h" 35f1d684faSDavid Nugent #include "pw.h" 36f1d684faSDavid Nugent 37f1d684faSDavid Nugent static int 38f1d684faSDavid Nugent pw_nisupdate(const char * path, struct passwd * pwd, char const * user, int mode) 39f1d684faSDavid Nugent { 40f1d684faSDavid Nugent char pfx[32]; 41f1d684faSDavid Nugent char pwbuf[PWBUFSZ]; 42f1d684faSDavid Nugent int l = sprintf(pfx, "%s:", user); 43f1d684faSDavid Nugent 44f1d684faSDavid Nugent /* 45f1d684faSDavid Nugent * Update the passwd file first 46f1d684faSDavid Nugent */ 47f1d684faSDavid Nugent if (pwd == NULL) 48f1d684faSDavid Nugent *pwbuf = '\0'; 49f1d684faSDavid Nugent else 50f1d684faSDavid Nugent fmtpwentry(pwbuf, pwd, PWF_MASTER); 51f1d684faSDavid Nugent return fileupdate(path, 0600, pwbuf, pfx, l, mode) != 0; 52f1d684faSDavid Nugent } 53f1d684faSDavid Nugent 54f1d684faSDavid Nugent int 55f1d684faSDavid Nugent addnispwent(const char *path, struct passwd * pwd) 56f1d684faSDavid Nugent { 57f1d684faSDavid Nugent return pw_nisupdate(path, pwd, pwd->pw_name, UPD_CREATE); 58f1d684faSDavid Nugent } 59f1d684faSDavid Nugent 60f1d684faSDavid Nugent int 61f1d684faSDavid Nugent chgnispwent(const char *path, char const * login, struct passwd * pwd) 62f1d684faSDavid Nugent { 63f1d684faSDavid Nugent return pw_nisupdate(path, pwd, login, UPD_REPLACE); 64f1d684faSDavid Nugent } 65f1d684faSDavid Nugent 66f1d684faSDavid Nugent int 67f1d684faSDavid Nugent delnispwent(const char *path, const char *login) 68f1d684faSDavid Nugent { 69f1d684faSDavid Nugent return pw_nisupdate(path, NULL, login, UPD_DELETE); 70f1d684faSDavid Nugent } 71