Commit Graph

429 Commits

Author SHA1 Message Date
bapt
87d5fd23fe Remove useless assignement of linelen 2015-12-29 00:02:08 +00:00
bapt
abb886fc3d Restore dryrun support for pw groupmod 2015-12-28 23:57:22 +00:00
bapt
9d1a130e58 pw_checkname since the beginning if too strict on GECOS field,
relax it a bit so gecos can be used to store multibytes data.

This was unseen before FreeBSD 10.2 as this validation function was motly unused
since FreeBSD 10.2 the usage of this function has been generalized to improve
validation.

Reported by:	des
MFC after:	1 week
2015-12-02 22:35:25 +00:00
bapt
5df8300abf Fix handling of numeric-only names with pw lock
Add a regression test about it

PR:		204968
MFC after:	1 week
2015-12-02 22:01:37 +00:00
delphij
2e85b00467 In pw_userlock, set 'name' to NULL when we encounter an all number string
because it is also used as an indicator of whether a name or an UID is
being used and we may have undefined results as 'name' may contain
uninitialized stack contents.

MFC after:	2 weeks
2015-10-30 00:46:52 +00:00
bdrewery
ef07697d65 Fix unlikely memory leak.
It is unlikely since the first check in the function is that dir[0] is '/',
but later code changes may make it real.

Coverity CID:	1332104
2015-10-29 18:29:28 +00:00
ngie
02a1e0f621 Initialize quiet to false so pw groupnext again prints out the next gid
by default

Reported by: Florian Degner <f.degner@gmx.de>
MFC after: 1 week
PR: 203876
Sponsored by: EMC / Isilon Storage Division
2015-10-19 18:29:32 +00:00
ngie
dd1f618367 Refactor the test/ Makefiles after recent changes to bsd.test.mk (r289158) and
netbsd-tests.test.mk (r289151)

- Eliminate explicit OBJTOP/SRCTOP setting
- Convert all ad hoc NetBSD test integration over to netbsd-tests.test.mk
- Remove unnecessary TESTSDIR setting
- Use SRCTOP where possible for clarity

MFC after: 2 weeks
Sponsored by: EMC / Isilon Storage Divison
2015-10-12 08:16:03 +00:00
wblock
deaa35894c Fix a repeated typo: rootir -> rootdir.
Approved by:	bapt
MFC after:	1 week
2015-10-09 14:55:55 +00:00
bapt
7322dfff51 Regression: fix usershow -7
Submitted by:	Dan McGregor (via IRC)
MFC after:	2 days
2015-09-14 19:23:00 +00:00
bapt
951f381262 Regression: fix pw usermod -d
Mark the user has having been edited if -d option is passed to usermod and
so the request change of home directory actually happen

PR:		203052
Reported by:	lenzi.sergio@gmail.com
MFC after:	2 days
2015-09-12 08:24:25 +00:00
bapt
43164ff2ed Fix err pointer not initialized to NULL resulting
Reported by:	"O. Hartmann" <ohartman@zedat.fu-berlin.de>
2015-08-21 14:28:14 +00:00
bapt
e991a153bd Fix typo in regression test 2015-08-21 11:25:42 +00:00
bapt
d36fba16cb Fix /home symlink creation
Add regression test about it
2015-08-21 09:28:20 +00:00
bapt
75130e0bf3 Fix useradd regression:
Readd the function to create the parents home directory if it does not exists.
if it is only a directory at the top level of the hierarchy symlink it into /usr
as it used to be done before.

Reported by:	kevlo, adrian
2015-08-21 07:09:53 +00:00
bapt
d8c0f52c74 Regression: fix pw usermod -w xxx
Reported by:	gjb
2015-08-14 13:39:55 +00:00
bapt
f8f56ae6ef Add regression tests for a bug reported in stable/10
While pw(8) on head is not affected it is worth adding more regression tests
ensuring this bug will not happen unnoticed in the futur
2015-08-05 21:11:32 +00:00
ed
08ce46330f Avoid calling strlen() where we can use the strspn() return value. 2015-08-03 22:07:50 +00:00
dteske
ce892f6643 Clarify pw(8) manual w/respect to required arguments. Break long lines at
punctuation while here.

Differential Revision:	https://reviews.freebsd.org/D2700
Reviewed by:	wblock, bapt
MFC after:	3 days
X-MFC-to:	stable/10
2015-08-03 21:19:31 +00:00
bapt
eb6ff5c8b3 Fix bugs spotted by gcc
Reported by:	adrian
2015-08-03 06:06:56 +00:00
adrian
a01e37a027 Actually set quiet to something.
/usr/home/adrian/work/freebsd/head-embedded-2/src/usr.sbin/pw/pw_user.c: In function 'pw_user_next':
/usr/home/adrian/work/freebsd/head-embedded-2/src/usr.sbin/pw/pw_user.c:680: warning: statement with no effect
2015-08-03 05:59:30 +00:00
bapt
9a7989cc8d Use intmax_t rather than long long 2015-08-02 19:49:24 +00:00
bapt
e969e86e40 Convert the year used for regression test fro 2043 to 2037
This makes the regression tests pass on systems where time_t is 32bits
2015-08-02 18:20:36 +00:00
bapt
069c5cd075 Fix build on 32bits 2015-08-02 13:50:11 +00:00
bapt
2c026ebb5c Split some extra long lines 2015-08-02 13:33:17 +00:00
bapt
2cfaa818a1 Split some extra long lines 2015-08-02 13:32:23 +00:00
bapt
4469579834 Cleanup a bit includes 2015-08-02 13:22:46 +00:00
bapt
8ca0483df0 Add regression tests about adding already existsing groups/users 2015-08-02 13:02:53 +00:00
bapt
4453f16adb Fix regression: report if a group already exists when creating it 2015-08-02 12:56:25 +00:00
bapt
521095bbe7 Fix regression: report again if a username already exists when creating it 2015-08-02 12:54:15 +00:00
bapt
1890bfce80 Remove dead code 2015-08-02 12:48:36 +00:00
bapt
4f6bdcfb5d Rewrite parsing subcommands arguments of pw(8)
Now each subcommands checks its arguments in a dedicated functions.

This helps improving input validation, code readability/maintainability
While here:
- Add a -y option to pw userdel/usermod so it can maintain NIS servers if
  nispasswd is not defined in pw.conf(5)
- Allow pw -r <rootdir> to remove directory with userdel -r
- Fix bug when renaming a user which was not renaming the user name it groups
  it is a member of.
- Only parse pw.conf(5) when needed.
2015-08-02 12:47:50 +00:00
bapt
f78f701a2d Remove netbsd tests on pw(8)
First they are redundant with the tests we currently have on pw(8)
Second they to modify the host database instead of being self contained withing
the test directory
2015-08-02 00:33:34 +00:00
bapt
e83b0ae9f0 Remove things that crept in after badly checked revert 2015-08-01 12:20:55 +00:00
bapt
8fa8b523a2 Partial revert of r286152
More work needed on the cli validation
2015-08-01 12:18:48 +00:00
bapt
353f021396 Fix build 2015-08-01 11:52:48 +00:00
bapt
626fd041e6 Fix formatting of new code
Fix sorting or errstr
Remove useless initialisation or errstr

Reported by:	bde
2015-08-01 11:31:59 +00:00
bapt
9a71628c9f Validate expiration days and password days from commmand line and pw.conf 2015-08-01 10:25:55 +00:00
bapt
10ba8e17a1 Validate the max_uid/max_gid boundaries and entry type in pw.conf 2015-08-01 10:10:13 +00:00
bapt
5acf1473e1 Cast uid/git to uintmax_t when using printf-like functions so the size of
uid/gid size remains a implementation detail
2015-08-01 09:55:47 +00:00
bapt
1567d1bb44 Improve strtounum
Fix many style bugs
Better variable naming
Use C99 'restrict' were apropriate
Fix potential errno race

Submitted by:	bde
2015-07-30 06:14:47 +00:00
bapt
d7ee5ad52d Cleanup includes 2015-07-29 23:26:18 +00:00
bapt
b34a90165d Actually set the proper license
Reported by:	trasz
2015-07-29 22:51:54 +00:00
bapt
dc24acf353 Actually add the new code 2015-07-29 06:23:06 +00:00
bapt
4eb9f59af4 Create a strtounum function using the same API as strtonum
This function returns uintmax_t
Use this function to convert to gid_t/uid_t
2015-07-29 06:22:41 +00:00
bapt
5d01982f6b Reject usermod and userdel if the user concerned is not on the user database
supposed to be manipulated

This prevent pw usermod creating a new local user when requesting to usermod on
a username is defined in LDAP.

This issue only happens when modifying the local user database (not inpacting
commands when -V or -R are used).

PR:		187653
Submitted by:	tmwalaszek@gmail.com
2015-07-28 21:49:38 +00:00
bapt
ae6e75a036 Check uid/gid used when creating a user/group are not larger than UID_MAX/GID_MAX
PR:		173977
Reported by:	nvass@gmx.com
2015-07-28 21:10:58 +00:00
bapt
39f3813b41 Fix wrong warning printed after changing or updating NIS users
PR:		37672
Submitted by:	chris+freebsd@chrullrich.de
2015-07-28 20:52:10 +00:00
bapt
6a2604d875 when -n is passed to any pw subcommand it is always expected to be considered as
a name so do not try to convert it to an id if it is a numeric value

PR:		31933
Reported by:	ted@impulse.net
Sponsored by:	gandi.net
2015-07-28 12:20:57 +00:00
bapt
ba90467d76 Really fix -o 2015-07-13 09:12:05 +00:00
bapt
3137e99447 Add regression tests to ensure we keep allowing creating users with uid0 2015-07-13 09:09:09 +00:00
bapt
bfc5fcd1dc Regression fix: allow to create users with uid0
Reported by:	Jan Mikkelsen <janm@transactionware.com>
2015-07-13 09:08:27 +00:00
bapt
7f2e5a63d2 Fix logic of check duplicates that has been inverted 2015-07-13 09:07:38 +00:00
bapt
e657e72f8d Ensure skeldir is abolute path (relatively to the rootdir) 2015-07-12 22:08:58 +00:00
bapt
16b27ac1cf pw -R <rootdir> userdel can now cleanup installation
Rewrite rm_r to use *at function, allowing to remove home directories along with
users. only crontabs and at(1) installation are not removed

Relnotes:	yes
2015-07-12 21:43:57 +00:00
bapt
8621997ee9 Rework the home directory creation and copy or the skel content to use *at
functions

This allows to simplify the code a bit for -R by not having to keep modifying
path and also prepare the code to improve support -R in userdel

While here, add regression tests for the functionality
2015-07-12 20:29:51 +00:00
bapt
084e0d801a Add minimum regression tests for pw -R 2015-07-12 09:42:10 +00:00
bapt
f15eb75bd0 Make getarg return NULL if args is NULL 2015-07-12 00:02:43 +00:00
bapt
2f9218d542 Fix regression: ensure when try to create the group and the user with the same
id if possible and nothing in particular was specified
2015-07-11 23:56:55 +00:00
bapt
13da2b2c87 Remove now unused variable 2015-07-11 23:17:13 +00:00
bapt
be61586cab Replace custom string array with stringlist(3) 2015-07-11 23:07:17 +00:00
bapt
a2b16f4acb Rework groupmod modification:
Use gr_add(3) when possible to avoid code duplication.
Use a simpler logic to delete members of a group
2015-07-11 22:35:07 +00:00
bapt
e3326739a7 Remove unused argument from pm_passwd 2015-07-11 21:12:28 +00:00
bapt
394857c344 check the gecos format early: at the moment the -c option is parsed 2015-07-11 21:09:50 +00:00
bapt
1f1e46ef86 Remove useless use of goto 2015-07-11 20:18:34 +00:00
bapt
7267051897 Isolate pw lock/unlock into a separate function 2015-07-11 20:10:12 +00:00
bapt
120396cfc3 homedir can only be populate during useradd 2015-07-11 19:14:09 +00:00
bapt
4c8679fa34 Make a separate groupdel/userdel from the main function 2015-07-11 19:07:47 +00:00
bapt
0ee1498c18 Make separate functions to show users and groups 2015-07-11 18:09:27 +00:00
bapt
4567491257 Move the quiet flag into the configuration structure 2015-07-11 17:01:08 +00:00
bapt
032c1600ec Separate usernext/groupnext from the main functions 2015-07-11 16:58:47 +00:00
bapt
f97075fb60 Do not try to set password on group if the group is added as a consequence of
of creating a user (regression from r285136)

Reported by:	Fabian Keil <fk@fabiankeil.de>
2015-07-09 14:14:44 +00:00
bapt
267e0f6761 pw: fail if an invalid entry is found while parsing master.passwd and group
PR:		198554
Reported by:	diaran <fbsd@centraltech.co.uk>
MFC after:	2 days
2015-07-07 21:05:20 +00:00
bapt
68ef3a03c5 Remove dead code 2015-07-05 10:14:34 +00:00
bapt
3023aa7e21 Also validate hours via strptime_l(3)
Simplify the code, by only using one parser, ensure the dates (hours and dates)
are valid
2015-07-05 10:11:35 +00:00
bapt
c4be172c20 Validate expiration dates
Use strptime_l(3) to validate the dates provided in input
2015-07-05 09:48:03 +00:00
bapt
db415bb5d6 Fix validation of crypted password
Small cleanups
2015-07-04 15:56:59 +00:00
bapt
f3cda7681e Also validate inputs of pw groupmod -h and groupmod -H 2015-07-04 15:54:11 +00:00
bapt
af8a9dfc9a Validate input of pw usermod -h and pwusermod -H
Push the code that set the password into a separate function to improve
readability

Add regression tests about pw usermod -h and pw usermod -H
2015-07-04 15:27:04 +00:00
bapt
2a257e3a0f Change the documentation to reflect where the -V option should be used
Suggested by:	kientzle
2015-06-14 21:50:38 +00:00
sjg
008d7c831f Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
sjg
75a137820d dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
bapt
ec480fe320 backout remove of -q option for pw [user|group] next
While the return code is broken, some corner case usage depends on the
functionnality, so backout until we get better regression tests covering those
corner case usage.
2015-06-08 05:27:34 +00:00
bapt
6e327f9366 Fix typo 2015-06-08 05:06:17 +00:00
bapt
2bc43a746d Fix mistakes than came along with r284139 2015-06-07 21:59:43 +00:00
bapt
65b30fab70 Remove '-q' support for pw [user|group] next
the intent of -q in this command is to return as exit status the value of the
next group/user id, which does not make sense given exit status are limited to
values between 0 and 255.
2015-06-07 21:57:20 +00:00
bapt
b0235ac2ee Fix setting uid/gid min/max via pw 2015-06-07 20:59:59 +00:00
bapt
fc781f489d Fix generating configuration file 2015-06-07 20:44:06 +00:00
bapt
302d4b4363 Fix duplicate checking 2015-06-07 19:59:01 +00:00
bapt
c668897924 Remove uneeded code (already done by pw_make_v7) 2015-06-07 19:39:06 +00:00
bapt
4a60f5b2aa In case of rename validate the length of the new name
Check early that the new name fits MAXLOGNAME and store it in pwconf
2015-06-07 19:33:25 +00:00
bapt
3be2bba5d7 Refactor input validation
Mutualize code to validate inputs of both 'user' and 'group' command
Test that the input name fits into MAXLOGNAME
2015-06-07 19:03:41 +00:00
bapt
28b61e032c Finish converting -7 to pwconf 2015-06-07 15:54:57 +00:00
bapt
87cd2261fe Handle -7 via gloval pwconf 2015-06-07 15:33:08 +00:00
bapt
9f5d2c6d19 Initialize conf using menset(3) 2015-06-07 15:29:58 +00:00
bapt
4ca3925ed2 Handle pretty print (-P) via global pwconf 2015-06-07 15:27:17 +00:00
bapt
720254061f Handle dryrun (-N) via global pwconf 2015-06-07 15:09:53 +00:00
bapt
cdf878c881 Sort headers 2015-06-07 14:57:16 +00:00
bapt
c79845f9d0 Handle -C and -Y locally and stop adding them to arglist 2015-06-07 14:54:07 +00:00
bapt
c6afeed630 Add a new global struct pwconf to store etcpath, rootdir and struct userconf
Do not add anymore -R and -V to arglist
Add an error message if both -V and -R are set in arguments
2015-06-07 14:34:38 +00:00