passwd: add UPN validation support#1633
Conversation
|
This is what I’ve managed to put in place with the time I had available... |
|
@MarcinDigitic do you mind testing? |
|
I've fixed several issues for you. v2:
range-diff |
4ea29c1 to
97b1a5c
Compare
| #include "sysconf.h" | ||
|
|
||
|
|
||
| #define DOMAIN_MAXLEN 253 |
There was a problem hiding this comment.
This seems to already account for the trailing root label, but if explicitly present, the limit is 254, AFAIK.
| if (strlen(domain) > DOMAIN_MAXLEN) { | ||
| errno = EOVERFLOW; | ||
| return false; | ||
| } |
There was a problem hiding this comment.
For accounting for the trailing root label correctly, regardless of whether it's implicit or explicit, this could be:
#define DOMAIN_MAXLEN 254
if (strlen(domain) + !!strrcspn(domain, ".") > DOMAIN_MAXLEN)97b1a5c to
0428dee
Compare
|
I've fixed a few more issues for you. v3:
range-diffv3b:
range-diff |
| if (optind < argc) { | ||
| if (!is_valid_user_name (argv[optind])) { | ||
| if (!is_valid_user_name (argv[optind]) && !is_valid_upn (argv[optind])) { | ||
| fprintf (stderr, _("%s: Provided user name is not a valid name\n"), Prog); | ||
| fail_exit (E_NOPERM, process_selinux); | ||
| } |
There was a problem hiding this comment.
Hmmmm, now I've realized another issue that was introduced when we added syntax checking of the user names. There's no way to relax the syntax checking, since passwd(1) has no --badname option. Thus, we've effectively removed --badname support.
We should probably also fix that.
There was a problem hiding this comment.
Maybe we should set badname to true in these programs that didn't check syntax before.
0428dee to
d2f556b
Compare
|
I realize that one of the unit tests is failing, I'll fix it when related PRs are merged and I can base my work on stable APIs |
I think the reason for the failing tests is that I changed the code to accept |
d71db36 to
c3625ee
Compare
|
I've fixed a few more things for you. v4:
range-diffv5:
range-diffDetails |
c3625ee to
48d9c38
Compare
| errno = EOVERFLOW; | ||
| return false; | ||
| } | ||
| if (!strcspn(label, "-") || label[strlen(label)-1] == '-') { |
There was a problem hiding this comment.
We still need strrcspn_() to replace the second test.
48d9c38 to
23c7a53
Compare
|
I've fixed a bug for you. v6:
range-diff |
|
I'm actively looking into this PR now that the dependencies are merged. Please do not push |
Add is_valid_upn() function to validate User Principal Name format. UPN validation splits on @ and validates the prefix using existing username rules and suffix part using RFC 1035/1123 compliant domain name validation. Link: <https://datatracker.ietf.org/doc/html/rfc1035#section-2.3.1> Co-authored-by: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com> Co-authored-by: Alejandro Colomar <alx@kernel.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Add comprehensive unit tests for is_valid_upn() function in `tests/unit/test_chkname.c` covering: - Valid UPN formats (user@domain.com) - Invalid structures (missing @, multiple @) - Domain validation (RFC compliance) - Boundary limits (253/254 char domains, 63+ char labels) Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Add User Principal Name (UPN) validation to allow passwd command to accept usernames in user@domain.com format. Currently, passwd will accept both traditional usernames and UPN format. Fixes: 326889c (2024-10-22; "Fix coverity unbound buffer issues") Closes: <shadow-maint#1626> Reported-by: @nooreldeenmansour Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Add User Principal Name (UPN) validation to allow
passwdcommand to accept usernames inuser@domain.comformat. This addresses rejection of valid UPN usernames by implementing proper RFC-compliant domain validation.Changes include:
is_valid_upn(), is_valid_domain_name(), andis_valid_domain_label()functions tolib/chkname.cwith RFC 1035/1123 compliant validationpasswd.cto accept both traditional usernames and UPN formatFixes: 326889c (2024-10-22; "Fix coverity unbound buffer issues")
Closes: #1626
Reported-by: @nooreldeenmansour
Supersedes: #1627