Deleted Added
full compact
pw_nis.c (50479) pw_nis.c (242349)
1/*-
2 * Copyright (C) 1996
3 * David L. Nugent. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#ifndef lint
28static const char rcsid[] =
1/*-
2 * Copyright (C) 1996
3 * David L. Nugent. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#ifndef lint
28static const char rcsid[] =
29 "$FreeBSD: head/usr.sbin/pw/pw_nis.c 50479 1999-08-28 01:35:59Z peter $";
29 "$FreeBSD: head/usr.sbin/pw/pw_nis.c 242349 2012-10-30 08:00:53Z bapt $";
30#endif /* not lint */
31
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <sys/types.h>
30#endif /* not lint */
31
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <sys/types.h>
36#include <err.h>
37#include <pwd.h>
38#include <libutil.h>
36
37#include "pw.h"
38
39static int
39
40#include "pw.h"
41
42static int
40pw_nisupdate(const char * path, struct passwd * pwd, char const * user, int mode)
43pw_nisupdate(const char * path, struct passwd * pwd, char const * user)
41{
44{
42 char pfx[32];
43 char pwbuf[PWBUFSZ];
44 int l = sprintf(pfx, "%s:", user);
45 int pfd, tfd;
46 struct passwd *pw = NULL;
47 struct passwd *old_pw = NULL;
45
48
46 /*
47 * Update the passwd file first
48 */
49 if (pwd == NULL)
50 *pwbuf = '\0';
51 else
52 fmtpwentry(pwbuf, pwd, PWF_MASTER);
53 return fileupdate(path, 0600, pwbuf, pfx, l, mode) != 0;
49 if (pwd != NULL)
50 pw = pw_dup(pwd);
51
52 if (user != NULL)
53 old_pw = GETPWNAM(user);
54
55 if (pw_init(NULL, path))
56 err(1,"pw_init()");
57 if ((pfd = pw_lock()) == -1) {
58 pw_fini();
59 err(1, "pw_lock()");
60 }
61 if ((tfd = pw_tmp(-1)) == -1) {
62 pw_fini();
63 err(1, "pw_tmp()");
64 }
65 if (pw_copy(pfd, tfd, pw, old_pw) == -1) {
66 pw_fini();
67 err(1, "pw_copy()");
68 }
69 if (rename(pw_tempname(), path) == -1)
70 err(1, "rename()");
71
72 free(pw);
73 pw_fini();
74
75 return (0);
54}
55
56int
57addnispwent(const char *path, struct passwd * pwd)
58{
76}
77
78int
79addnispwent(const char *path, struct passwd * pwd)
80{
59 return pw_nisupdate(path, pwd, pwd->pw_name, UPD_CREATE);
81 return pw_nisupdate(path, pwd, NULL);
60}
61
62int
63chgnispwent(const char *path, char const * login, struct passwd * pwd)
64{
82}
83
84int
85chgnispwent(const char *path, char const * login, struct passwd * pwd)
86{
65 return pw_nisupdate(path, pwd, login, UPD_REPLACE);
87 return pw_nisupdate(path, pwd, login);
66}
67
68int
69delnispwent(const char *path, const char *login)
70{
88}
89
90int
91delnispwent(const char *path, const char *login)
92{
71 return pw_nisupdate(path, NULL, login, UPD_DELETE);
93 return pw_nisupdate(path, NULL, login);
72}
94}