Deleted Added
full compact
pw_group.c (284149) pw_group.c (285136)
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_group.c 284149 2015-06-08 05:27:34Z bapt $";
29 "$FreeBSD: head/usr.sbin/pw/pw_group.c 285136 2015-07-04 15:54:11Z bapt $";
30#endif /* not lint */
31
32#include <ctype.h>
33#include <err.h>
34#include <termios.h>
35#include <stdbool.h>
36#include <unistd.h>
37#include <grp.h>

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

42
43
44static struct passwd *lookup_pwent(const char *user);
45static void delete_members(char ***members, int *grmembers, int *i,
46 struct carg *arg, struct group *grp);
47static int print_group(struct group * grp);
48static gid_t gr_gidpolicy(struct userconf * cnf, long id);
49
30#endif /* not lint */
31
32#include <ctype.h>
33#include <err.h>
34#include <termios.h>
35#include <stdbool.h>
36#include <unistd.h>
37#include <grp.h>

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

42
43
44static struct passwd *lookup_pwent(const char *user);
45static void delete_members(char ***members, int *grmembers, int *i,
46 struct carg *arg, struct group *grp);
47static int print_group(struct group * grp);
48static gid_t gr_gidpolicy(struct userconf * cnf, long id);
49
50static void
51set_passwd(struct group *grp, bool update)
52{
53 int b;
54 int istty;
55 struct termios t, n;
56 char *p, line[256];
57
58 if (conf.fd == '-') {
59 grp->gr_passwd = "*"; /* No access */
60 return;
61 }
62
63 if ((istty = isatty(conf.fd))) {
64 n = t;
65 /* Disable echo */
66 n.c_lflag &= ~(ECHO);
67 tcsetattr(conf.fd, TCSANOW, &n);
68 printf("%sassword for group %s:", update ? "New p" : "P",
69 grp->gr_name);
70 fflush(stdout);
71 }
72 b = read(conf.fd, line, sizeof(line) - 1);
73 if (istty) { /* Restore state */
74 tcsetattr(conf.fd, TCSANOW, &t);
75 fputc('\n', stdout);
76 fflush(stdout);
77 }
78 if (b < 0)
79 err(EX_OSERR, "-h file descriptor");
80 line[b] = '\0';
81 if ((p = strpbrk(line, " \t\r\n")) != NULL)
82 *p = '\0';
83 if (!*line)
84 errx(EX_DATAERR, "empty password read on file descriptor %d",
85 conf.fd);
86 if (conf.precrypted) {
87 if (strchr(line, ':') != 0)
88 errx(EX_DATAERR, "wrong encrypted passwrd");
89 grp->gr_passwd = line;
90 } else
91 grp->gr_passwd = pw_pwcrypt(line);
92}
93
50int
51pw_group(int mode, char *name, long id, struct cargs * args)
52{
53 int rc;
54 struct carg *arg;
55 struct group *grp = NULL;
56 int grmembers = 0;
57 char **members = NULL;

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

151
152 /*
153 * This allows us to set a group password Group passwords is an
154 * antique idea, rarely used and insecure (no secure database) Should
155 * be discouraged, but it is apparently still supported by some
156 * software.
157 */
158
94int
95pw_group(int mode, char *name, long id, struct cargs * args)
96{
97 int rc;
98 struct carg *arg;
99 struct group *grp = NULL;
100 int grmembers = 0;
101 char **members = NULL;

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

195
196 /*
197 * This allows us to set a group password Group passwords is an
198 * antique idea, rarely used and insecure (no secure database) Should
199 * be discouraged, but it is apparently still supported by some
200 * software.
201 */
202
159 if ((arg = getarg(args, 'h')) != NULL ||
160 (arg = getarg(args, 'H')) != NULL) {
161 if (strcmp(arg->val, "-") == 0)
162 grp->gr_passwd = "*"; /* No access */
163 else {
164 int fd = atoi(arg->val);
165 int precrypt = (arg->ch == 'H');
166 int b;
167 int istty = isatty(fd);
168 struct termios t;
169 char *p, line[256];
203 if (conf.fd != -1)
204 set_passwd(grp, mode == M_UPDATE);
170
205
171 if (istty) {
172 if (tcgetattr(fd, &t) == -1)
173 istty = 0;
174 else {
175 struct termios n = t;
176
177 /* Disable echo */
178 n.c_lflag &= ~(ECHO);
179 tcsetattr(fd, TCSANOW, &n);
180 printf("%sassword for group %s:", (mode == M_UPDATE) ? "New p" : "P", grp->gr_name);
181 fflush(stdout);
182 }
183 }
184 b = read(fd, line, sizeof(line) - 1);
185 if (istty) { /* Restore state */
186 tcsetattr(fd, TCSANOW, &t);
187 fputc('\n', stdout);
188 fflush(stdout);
189 }
190 if (b < 0)
191 err(EX_OSERR, "-h file descriptor");
192 line[b] = '\0';
193 if ((p = strpbrk(line, " \t\r\n")) != NULL)
194 *p = '\0';
195 if (!*line)
196 errx(EX_DATAERR, "empty password read on file descriptor %d", fd);
197 if (precrypt) {
198 if (strchr(line, ':') != NULL)
199 return EX_DATAERR;
200 grp->gr_passwd = line;
201 } else
202 grp->gr_passwd = pw_pwcrypt(line);
203 }
204 }
205
206 if (((arg = getarg(args, 'M')) != NULL ||
207 (arg = getarg(args, 'd')) != NULL ||
208 (arg = getarg(args, 'm')) != NULL) && arg->val) {
209 int i = 0;
210 char *p;
211 struct passwd *pwd;
212
213 /* Make sure this is not stay NULL with -M "" */

--- 209 unchanged lines hidden ---
206 if (((arg = getarg(args, 'M')) != NULL ||
207 (arg = getarg(args, 'd')) != NULL ||
208 (arg = getarg(args, 'm')) != NULL) && arg->val) {
209 int i = 0;
210 char *p;
211 struct passwd *pwd;
212
213 /* Make sure this is not stay NULL with -M "" */

--- 209 unchanged lines hidden ---