Skip to content

src/login_nopam.c: Simplify some code#1643

Open
alejandro-colomar wants to merge 12 commits into
shadow-maint:masterfrom
alejandro-colomar:sm
Open

src/login_nopam.c: Simplify some code#1643
alejandro-colomar wants to merge 12 commits into
shadow-maint:masterfrom
alejandro-colomar:sm

Conversation

@alejandro-colomar

@alejandro-colomar alejandro-colomar commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Revisions:

v1b
  • Rebase
$ git rd 
 1:  3bac26354724 =  1:  537b6a03a677 src/login_nopam.c: Remove string_match()
 2:  9edd0a0e727e !  2:  51b1f587df4a src/login_nopam.c: from_match(): Unify style of conditionals
    @@ src/login_nopam.c: static bool from_match (char *tok, const char *string)
        } else if (strcaseeq(tok, "LOCAL")) {   /* LOCAL: no dots */
                if (!strchr(string, '.'))
                        return true;
    --  } else if (   (!streq(tok, "") && tok[strlen(tok) - 1] == '.') /* network */
    +-  } else if (   strrspn_(tok, ".")  /* network */
     -             && strprefix(resolve_hostname(string), tok)) {
     -          return true;
    -+  } else if (!streq(tok, "") && tok[strlen(tok) - 1] == '.') {  /* network */
    ++  } else if (strrspn_(tok, ".")  /* network */
     +          if (strprefix(resolve_hostname(string), tok))
     +                  return true;
        }
 3:  fadafa8fa947 !  3:  36478c11ea60 src/login_nopam.c: from_match(): return directly in all cases
    @@ src/login_nopam.c: static bool from_match (char *tok, const char *string)
     -          if (!strchr(string, '.'))
     -                  return true;
     +          return !strchr(string, '.');
    -   } else if (!streq(tok, "") && tok[strlen(tok) - 1] == '.') {  /* network */
    +   } else if (strrspn_(tok, ".")  /* network */
     -          if (strprefix(resolve_hostname(string), tok))
     -                  return true;
     +          return !!strprefix(resolve_hostname(string), tok);
 4:  2f39983c89a1 !  4:  fd970d49750a src/login_nopam.c: Don't else after return
    @@ src/login_nopam.c: static bool from_match (char *tok, const char *string)
                return str_len > tok_len && strcaseeq(tok, string + str_len - tok_len);
     -  } else if (strcaseeq(tok, "LOCAL")) {   /* LOCAL: no dots */
     -          return !strchr(string, '.');
    --  } else if (!streq(tok, "") && tok[strlen(tok) - 1] == '.') {  /* network */
    +-  } else if (strrspn_(tok, ".")  /* network */
     -          return !!strprefix(resolve_hostname(string), tok);
        }
     +  if (strcaseeq(tok, "LOCAL"))  /* LOCAL: no dots */
     +          return !strchr(string, '.');
    -+  if (!streq(tok, "") && tok[strlen(tok) - 1] == '.')  /* network */
    ++  if (strrspn_(tok, ".")  /* network */
     +          return !!strprefix(resolve_hostname(string), tok);
        return false;
      }
 5:  320b5ddc98c3 =  5:  a3638b9f27a5 src/login_nopam.c: login_access(): Reduce scope of local variables
 6:  d6264edfdf72 =  6:  1244697a7ee2 src/login_nopam.c: login_access(): Move error handling earlier
 7:  1dbaed7b1ea3 =  7:  566fa2f5b140 src/login_nopam.c: login_access(): Reduce indentation
 8:  30c20ba4ca8c =  8:  d209643e619f src/login_nopam.c: login_access(): Use for instead of while loop
 9:  f999479e2bf9 =  9:  08befd50450d src/login_nopam.c: login_access(): Handle a match earlier
10:  2b5979522d4f = 10:  88841c86aab2 src/login_nopam.c: login_access(): Consistently use 'perm'
11:  dd0fd366ea1b = 11:  a2606232519e src/login_nopam.c: login_access(): Remove redundant comments
12:  3fe331f1e6a8 = 12:  7cc582ca3765 lib/, src/login_nopam.c: login_access(): Return bool

@alejandro-colomar alejandro-colomar self-assigned this Jun 13, 2026
@alejandro-colomar alejandro-colomar changed the title src/login_nopam.c: Remove string_match() src/login_nopam.c: Simplify some code Jun 14, 2026
@alejandro-colomar alejandro-colomar force-pushed the sm branch 8 times, most recently from 1012790 to 3fe331f Compare June 14, 2026 13:59
Calling strcaseeq() explicitly is more readable, and it allows removing
the comments.  The code becomes simpler.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This simplifies the conditionals, allowing the removal of 'else's.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This will allow reducing indentation for the rest of the code.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
And rename the iterator to the usual 'i'.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This makes the logic more readable, and removes one variable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
line and perm point to the same thing, but perm is more appropriate.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
And remove some superfluous braces.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant