Add some wrappers for usual loops around strsep(3)#1155
Merged
alejandro-colomar merged 11 commits intoJun 7, 2025
Conversation
8b6cac1 to
040a7ac
Compare
040a7ac to
729949b
Compare
b4ce84c to
0413de0
Compare
0413de0 to
b93cc4d
Compare
2e6ef4b to
de41126
Compare
7f723f5 to
b53790c
Compare
b53790c to
be9ecea
Compare
be9ecea to
e138692
Compare
e138692 to
14df6eb
Compare
Closed
eeed3c6 to
9d3ce19
Compare
9d3ce19 to
18055c2
Compare
hallyn
reviewed
Jun 6, 2025
hallyn
reviewed
Jun 6, 2025
alejandro-colomar
added a commit
to alejandro-colomar/shadow
that referenced
this pull request
Jun 6, 2025
This array is only ever used as an array of 7.
alx@devuan:/srv/alx/src/shadow/shadow/master$ sed_rm_ccomments()
{
perl -p -e 's%/\*.*?\*/%%g' \
|sed -E '\%/\*%, \%\*/% {\%(\*/|/\*)%!d}' \
|sed -E '\%/\*% {s%/\*.*%%; n; s%.*\*/%%;}' \
|sed -E '\%/\*% {s%/\*.*%%; n; s%.*\*/%%;}' \
|sed 's%//.*%%';
}
alx@devuan:/srv/alx/src/shadow/shadow/master$ cat src/newusers.c | grepc main | sed_rm_ccomments | grep -nT 'n\?fields\(\[.*]\)\?'
4: char *fields[8];
5: int nfields;
59: for (cp = buf, nfields = 0; nfields < 7; nfields++) {
60: fields[nfields] = strsep(&cp, ":");
64: if (nfields != 6) {
72: pw = pw_locate (fields[0]);
74: if (NULL == pw && getpwnam(fields[0]) != NULL) {
77: Prog, fields[0]);
81: if (NULL == pw && get_user_id(fields[2], &uid) != 0) {
91: && (add_group (fields[0], fields[3], &gid, uid) != 0)) {
101: && (add_user (fields[0], uid, gid) != 0)) {
110: pw = pw_locate (fields[0]);
114: Prog, line, fields[0], pw_dbname ());
132: usernames[nusers-1] = xstrdup(fields[0]);
133: passwords[nusers-1] = xstrdup(fields[1]);
135: if (add_passwd (&newpw, fields[1]) != 0) {
141: if (!streq(fields[4], "")) {
142: newpw.pw_gecos = fields[4];
145: if (!streq(fields[5], "")) {
146: newpw.pw_dir = fields[5];
149: if (!streq(fields[6], "")) {
150: newpw.pw_shell = fields[6];
153: if ( !streq(fields[5], "")
195: if (is_sub_uid && want_subuids() && !local_sub_uid_assigned(fields[0])) {
205: if (sub_uid_add(fields[0], sub_uid_start, sub_uid_count) == 0)
216: if (is_sub_gid && want_subgids() && !local_sub_gid_assigned(fields[0])) {
225: if (sub_gid_add(fields[0], sub_gid_start, sub_gid_count) == 0) {
alx@devuan:/srv/alx/src/shadow/shadow/master$ cat src/newusers.c | grepc main | sed_rm_ccomments | grep -nTo 'n\?fields\(\[.*]\)\?'
4: fields[8]
5: nfields
59: nfields
59: nfields
59: nfields
60: fields[nfields]
64: nfields
72: fields[0]
74: fields[0]
77: fields[0]
81: fields[2]
91: fields[0], fields[3]
101: fields[0]
110: fields[0]
114: fields[0]
132: fields[0]
133: fields[1]
135: fields[1]
141: fields[4]
142: fields[4]
145: fields[5]
146: fields[5]
149: fields[6]
150: fields[6]
153: fields[5]
195: fields[0]
205: fields[0]
216: fields[0]
225: fields[0]
Link: <shadow-maint#1155 (comment)>
Signed-off-by: Alejandro Colomar <[email protected]>
Collaborator
Author
|
I've addressed in v8 the two issues you reported, @hallyn . Thanks for reviewing! |
848e778 to
08ea2bf
Compare
alejandro-colomar
added a commit
to alejandro-colomar/shadow
that referenced
this pull request
Jun 6, 2025
This array is only ever used as an array of 7.
alx@devuan:/srv/alx/src/shadow/shadow/master$ sed_rm_ccomments()
{
perl -p -e 's%/\*.*?\*/%%g' \
|sed -E '\%/\*%, \%\*/% {\%(\*/|/\*)%!d}' \
|sed -E '\%/\*% {s%/\*.*%%; n; s%.*\*/%%;}' \
|sed -E '\%/\*% {s%/\*.*%%; n; s%.*\*/%%;}' \
|sed 's%//.*%%';
}
alx@devuan:/srv/alx/src/shadow/shadow/master$ cat src/newusers.c | grepc main | sed_rm_ccomments | grep -nT 'n\?fields\(\[.*]\)\?'
4: char *fields[8];
5: int nfields;
59: for (cp = buf, nfields = 0; nfields < 7; nfields++) {
60: fields[nfields] = strsep(&cp, ":");
64: if (nfields != 6) {
72: pw = pw_locate (fields[0]);
74: if (NULL == pw && getpwnam(fields[0]) != NULL) {
77: Prog, fields[0]);
81: if (NULL == pw && get_user_id(fields[2], &uid) != 0) {
91: && (add_group (fields[0], fields[3], &gid, uid) != 0)) {
101: && (add_user (fields[0], uid, gid) != 0)) {
110: pw = pw_locate (fields[0]);
114: Prog, line, fields[0], pw_dbname ());
132: usernames[nusers-1] = xstrdup(fields[0]);
133: passwords[nusers-1] = xstrdup(fields[1]);
135: if (add_passwd (&newpw, fields[1]) != 0) {
141: if (!streq(fields[4], "")) {
142: newpw.pw_gecos = fields[4];
145: if (!streq(fields[5], "")) {
146: newpw.pw_dir = fields[5];
149: if (!streq(fields[6], "")) {
150: newpw.pw_shell = fields[6];
153: if ( !streq(fields[5], "")
195: if (is_sub_uid && want_subuids() && !local_sub_uid_assigned(fields[0])) {
205: if (sub_uid_add(fields[0], sub_uid_start, sub_uid_count) == 0)
216: if (is_sub_gid && want_subgids() && !local_sub_gid_assigned(fields[0])) {
225: if (sub_gid_add(fields[0], sub_gid_start, sub_gid_count) == 0) {
alx@devuan:/srv/alx/src/shadow/shadow/master$ cat src/newusers.c | grepc main | sed_rm_ccomments | grep -nTo 'n\?fields\(\[.*]\)\?'
4: fields[8]
5: nfields
59: nfields
59: nfields
59: nfields
60: fields[nfields]
64: nfields
72: fields[0]
74: fields[0]
77: fields[0]
81: fields[2]
91: fields[0], fields[3]
101: fields[0]
110: fields[0]
114: fields[0]
132: fields[0]
133: fields[1]
135: fields[1]
141: fields[4]
142: fields[4]
145: fields[5]
146: fields[5]
149: fields[6]
150: fields[6]
153: fields[5]
195: fields[0]
205: fields[0]
216: fields[0]
225: fields[0]
Fixes: 45c6603 (2007-10-07; "[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Link: <shadow-maint#1155 (comment)>
Signed-off-by: Alejandro Colomar <[email protected]>
Closed
hallyn
approved these changes
Jun 7, 2025
Member
hallyn
left a comment
There was a problem hiding this comment.
Thanks, lgtm. You had it as draft so I'lleave it to you to merge assuming you think it ready.
This was referenced Jun 7, 2025
08ea2bf to
534cb2a
Compare
Collaborator
Author
I have rebased on top of #1266 . I prefer if this is not merged before that one. I will keep this open, and will leave it up to you to merge, after that one, since I'll be AFK until the UTC afternoon. |
hallyn
pushed a commit
that referenced
this pull request
Jun 7, 2025
This array is only ever used as an array of 7.
alx@devuan:/srv/alx/src/shadow/shadow/master$ sed_rm_ccomments()
{
perl -p -e 's%/\*.*?\*/%%g' \
|sed -E '\%/\*%, \%\*/% {\%(\*/|/\*)%!d}' \
|sed -E '\%/\*% {s%/\*.*%%; n; s%.*\*/%%;}' \
|sed -E '\%/\*% {s%/\*.*%%; n; s%.*\*/%%;}' \
|sed 's%//.*%%';
}
alx@devuan:/srv/alx/src/shadow/shadow/master$ cat src/newusers.c | grepc main | sed_rm_ccomments | grep -nT 'n\?fields\(\[.*]\)\?'
4: char *fields[8];
5: int nfields;
59: for (cp = buf, nfields = 0; nfields < 7; nfields++) {
60: fields[nfields] = strsep(&cp, ":");
64: if (nfields != 6) {
72: pw = pw_locate (fields[0]);
74: if (NULL == pw && getpwnam(fields[0]) != NULL) {
77: Prog, fields[0]);
81: if (NULL == pw && get_user_id(fields[2], &uid) != 0) {
91: && (add_group (fields[0], fields[3], &gid, uid) != 0)) {
101: && (add_user (fields[0], uid, gid) != 0)) {
110: pw = pw_locate (fields[0]);
114: Prog, line, fields[0], pw_dbname ());
132: usernames[nusers-1] = xstrdup(fields[0]);
133: passwords[nusers-1] = xstrdup(fields[1]);
135: if (add_passwd (&newpw, fields[1]) != 0) {
141: if (!streq(fields[4], "")) {
142: newpw.pw_gecos = fields[4];
145: if (!streq(fields[5], "")) {
146: newpw.pw_dir = fields[5];
149: if (!streq(fields[6], "")) {
150: newpw.pw_shell = fields[6];
153: if ( !streq(fields[5], "")
195: if (is_sub_uid && want_subuids() && !local_sub_uid_assigned(fields[0])) {
205: if (sub_uid_add(fields[0], sub_uid_start, sub_uid_count) == 0)
216: if (is_sub_gid && want_subgids() && !local_sub_gid_assigned(fields[0])) {
225: if (sub_gid_add(fields[0], sub_gid_start, sub_gid_count) == 0) {
alx@devuan:/srv/alx/src/shadow/shadow/master$ cat src/newusers.c | grepc main | sed_rm_ccomments | grep -nTo 'n\?fields\(\[.*]\)\?'
4: fields[8]
5: nfields
59: nfields
59: nfields
59: nfields
60: fields[nfields]
64: nfields
72: fields[0]
74: fields[0]
77: fields[0]
81: fields[2]
91: fields[0], fields[3]
101: fields[0]
110: fields[0]
114: fields[0]
132: fields[0]
133: fields[1]
135: fields[1]
141: fields[4]
142: fields[4]
145: fields[5]
146: fields[5]
149: fields[6]
150: fields[6]
153: fields[5]
195: fields[0]
205: fields[0]
216: fields[0]
225: fields[0]
Fixes: 45c6603 (2007-10-07; "[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Link: <#1155 (comment)>
Signed-off-by: Alejandro Colomar <[email protected]>
This API set implements the usual loop around strsep(3). This one implements a loop where we are interested in an exact number of fields. I'll add another API set, strsep2ls() and STRSEP2LS(), which will add a NULL terminator, for arbitrary numbers of fields. Signed-off-by: Alejandro Colomar <[email protected]>
This API set implements another usual loop around strsep(3). This one implements a loop where we are interested in an arbitrary number of fields. For that, a NULL terminator is added at the end. That is commonly referred to as "list". Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
This makes it clear we wipe anything that was in the buffer. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
534cb2a to
01bed8a
Compare
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Suggested-by: @hallyn
Revisions:
v2
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118044
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118043
v2b
v2c
v2d
v2e
v3
v4
v4b
v5
v5b
v5c
v5d
v5e
v5f
v5g
v5h
v6
v7
v7b
v7c
v7d
v7e
v7f
v8
v9
v9b