pw_nis.c revision 267654
1193323Sed/*- 2193323Sed * Copyright (C) 1996 3193323Sed * David L. Nugent. All rights reserved. 4193323Sed * 5193323Sed * Redistribution and use in source and binary forms, with or without 6193323Sed * modification, are permitted provided that the following conditions 7193323Sed * are met: 8193323Sed * 1. Redistributions of source code must retain the above copyright 9193323Sed * notice, this list of conditions and the following disclaimer. 10193323Sed * 2. Redistributions in binary form must reproduce the above copyright 11193323Sed * notice, this list of conditions and the following disclaimer in the 12193323Sed * documentation and/or other materials provided with the distribution. 13204961Srdivacky * 14280031Sdim * THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND 15276479Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16261991Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17288943Sdim * ARE DISCLAIMED. IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE 18280031Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19280031Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20276479Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21249423Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22249423Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23249423Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24249423Sdim * SUCH DAMAGE. 25280031Sdim */ 26198090Srdivacky 27193323Sed#ifndef lint 28249423Sdimstatic const char rcsid[] = 29276479Sdim "$FreeBSD: releng/9.3/usr.sbin/pw/pw_nis.c 50479 1999-08-28 01:35:59Z peter $"; 30249423Sdim#endif /* not lint */ 31276479Sdim 32249423Sdim#include <stdio.h> 33249423Sdim#include <stdlib.h> 34276479Sdim#include <string.h> 35204961Srdivacky#include <sys/types.h> 36296417Sdim 37198090Srdivacky#include "pw.h" 38198090Srdivacky 39204961Srdivackystatic int 40207618Srdivackypw_nisupdate(const char * path, struct passwd * pwd, char const * user, int mode) 41198090Srdivacky{ 42261991Sdim char pfx[32]; 43276479Sdim char pwbuf[PWBUFSZ]; 44198090Srdivacky int l = sprintf(pfx, "%s:", user); 45202878Srdivacky 46276479Sdim /* 47261991Sdim * Update the passwd file first 48249423Sdim */ 49193323Sed if (pwd == NULL) 50288943Sdim *pwbuf = '\0'; 51249423Sdim else 52249423Sdim fmtpwentry(pwbuf, pwd, PWF_MASTER); 53249423Sdim return fileupdate(path, 0600, pwbuf, pfx, l, mode) != 0; 54249423Sdim} 55249423Sdim 56280031Sdimint 57193323Sedaddnispwent(const char *path, struct passwd * pwd) 58193323Sed{ 59276479Sdim return pw_nisupdate(path, pwd, pwd->pw_name, UPD_CREATE); 60276479Sdim} 61261991Sdim 62261991Sdimint 63261991Sdimchgnispwent(const char *path, char const * login, struct passwd * pwd) 64207618Srdivacky{ 65261991Sdim return pw_nisupdate(path, pwd, login, UPD_REPLACE); 66261991Sdim} 67261991Sdim 68261991Sdimint 69208599Srdivackydelnispwent(const char *path, const char *login) 70261991Sdim{ 71261991Sdim return pw_nisupdate(path, NULL, login, UPD_DELETE); 72261991Sdim} 73261991Sdim