Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename get[u]long() to str2[su]l(), and add a more featureful a2[su]l(); add variants for other types too #891

Merged
merged 4 commits into from
Mar 29, 2024

Conversation

alejandro-colomar
Copy link
Collaborator

These will replace more strto[u][l]l(3) calls, improving type safety.

@alejandro-colomar alejandro-colomar force-pushed the getlong branch 17 times, most recently from 88d3b3c to 646bab5 Compare January 11, 2024 10:11
@alejandro-colomar alejandro-colomar force-pushed the getlong branch 3 times, most recently from 4924d43 to 5a67b15 Compare January 17, 2024 01:23
@alejandro-colomar alejandro-colomar changed the title Rename get[u]long() into get[u]l(), and add a more featureful get[u]long() Rename get[u]long() into str2[su]l(), and add a more featureful a2[su]l() Jan 17, 2024
@alejandro-colomar alejandro-colomar changed the title Rename get[u]long() into str2[su]l(), and add a more featureful a2[su]l() Rename get[u]long() into str2[su]l(), and add a more featureful a2[su]l(); add variants for other types too Jan 17, 2024
@alejandro-colomar alejandro-colomar changed the title Rename get[u]long() into str2[su]l(), and add a more featureful a2[su]l(); add variants for other types too Rename get[u]long() to str2[su]l(), and add a more featureful a2[su]l(); add variants for other types too Jan 17, 2024
@alejandro-colomar alejandro-colomar force-pushed the getlong branch 3 times, most recently from bac0ffd to a6cca1c Compare January 21, 2024 00:39
@alejandro-colomar alejandro-colomar marked this pull request as ready for review February 6, 2024 01:22
@alejandro-colomar alejandro-colomar marked this pull request as draft February 13, 2024 22:20
@alejandro-colomar
Copy link
Collaborator Author

v2 changes:

  • Rebase to master
$ git range-diff alx/master..gh/getlong shadow/master..getlong 
1:  f95e7dcf = 1:  0cdbaae1 lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
2:  a762bff2 = 2:  bf5e56ac lib/atoi/: Add a2[su]l() and reimplement get[u]long() in terms of them
3:  27a4607b ! 3:  b01bf54e lib/, src/: str2*(): Rename functions and reorder parameters
    @@ lib/limits.c: void setup_limits (const struct passwd *info)
                                                 "Can't set umask value for user %s",
     
      ## lib/rlogin.c ##
    -@@ lib/rlogin.c: do_rlogin (const char *remote_host, char *name, size_t namelen, char *term,
    +@@ lib/rlogin.c: do_rlogin(const char *remote_host, char *name, size_t namesize, char *term,
                *cp = '\0';
                cp++;
      
4:  8224f590 = 4:  df5fcef9 lib/atoi/: a2*(), str2*(): Add variants for other types

@alejandro-colomar alejandro-colomar marked this pull request as ready for review February 19, 2024 16:36
@alejandro-colomar
Copy link
Collaborator Author

v2b changes:

  • Rebase to master
$ git range-diff 0cdbaae1^..gh/getlong shadow/master..getlong 
1:  0cdbaae1 = 1:  1974802a lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
2:  bf5e56ac = 2:  ba573c4b lib/atoi/: Add a2[su]l() and reimplement get[u]long() in terms of them
3:  b01bf54e = 3:  7b548177 lib/, src/: str2*(): Rename functions and reorder parameters
4:  df5fcef9 = 4:  15dc249b lib/atoi/: a2*(), str2*(): Add variants for other types

@alejandro-colomar
Copy link
Collaborator Author

v2c changes:

  • Rebase to master
$ git range-diff gh/master..gh/getlong alx/master..getlong 
1:  1974802a = 1:  37054c87 lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
2:  ba573c4b = 2:  283867e0 lib/atoi/: Add a2[su]l() and reimplement get[u]long() in terms of them
3:  7b548177 = 3:  49221dea lib/, src/: str2*(): Rename functions and reorder parameters
4:  15dc249b = 4:  32a2874a lib/atoi/: a2*(), str2*(): Add variants for other types

@hallyn
Copy link
Member

hallyn commented Mar 11, 2024

(still looking at this... it looks ok, but looks sensitivee)

@alejandro-colomar
Copy link
Collaborator Author

Thanks!

@alejandro-colomar
Copy link
Collaborator Author

v2d changes:

  • Rebase to master
$ git range-diff 89c4da43..gh/getlong alx/master..getlong 
1:  37054c87 = 1:  83498640 lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
2:  283867e0 = 2:  4c6a26b0 lib/atoi/: Add a2[su]l() and reimplement get[u]long() in terms of them
3:  49221dea = 3:  14910115 lib/, src/: str2*(): Rename functions and reorder parameters
4:  32a2874a = 4:  3ca0de33 lib/atoi/: a2*(), str2*(): Add variants for other types

lib/atoi/a2i.h Show resolved Hide resolved
@alejandro-colomar
Copy link
Collaborator Author

v3 changes:

  • Rebase to master
$ git range-diff master..gh/getlong alx/master..getlong 
1:  83498640 ! 1:  f473ccd7 lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
    @@ lib/rlogin.c
     
      ## lib/sgetspent.c ##
     @@
    + #include <sys/types.h>
    + #include <string.h>
    + 
    ++#include "atoi/str2i.h"
    + #include "prototypes.h"
      #include "shadowlog_internal.h"
      #include "defines.h"
    - #include <stdio.h>
    -+
    -+#include "atoi/str2i.h"
    -+
    -+
    - #define   FIELDS  9
    - #define   OFIELDS 5
    - /*
     
      ## lib/shadow.c ##
     @@
    - #include "prototypes.h"
      #include "defines.h"
      #include <stdio.h>
    -+
    + 
     +#include "atoi/str2i.h"
     +
    -+
    - #ifdef    USE_NIS
    - static bool nis_used;
    - static bool nis_ignore;
    + 
    + static FILE *shadow;
    + 
     
      ## lib/strtoday.c ##
     @@
    @@ lib/strtoday.c
     
      ## lib/subordinateio.c ##
     @@
    - #include <fcntl.h>
    + #include <string.h>
      
      #include "alloc.h"
     +#include "atoi/str2i.h"
    @@ src/chage.c
      
      #include "alloc.h"
     +#include "atoi/str2i.h"
    - #include "prototypes.h"
      #include "defines.h"
      #include "memzero.h"
    + #include "prototypes.h"
     
      ## src/chgpasswd.c ##
     @@
    @@ src/passwd.c
      #include "getdef.h"
      #include "memzero.h"
     @@
    - #include "shadowlog.h"
    - #include "string/strtcpy.h"
    + #include "time/day_to_str.h"
    + 
      
     +
      /*
2:  4c6a26b0 = 2:  83518d40 lib/atoi/: Add a2[su]l() and reimplement get[u]long() in terms of them
3:  14910115 ! 3:  b3bd3d68 lib/, src/: str2*(): Rename functions and reorder parameters
    @@ lib/rlogin.c: do_rlogin(const char *remote_host, char *name, size_t namesize, ch
             (   (speed_table[i].spd_baud != remote_speed)
     
      ## lib/sgetspent.c ##
    -@@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
    +@@ lib/sgetspent.c: sgetspent(const char *string)
      
        if (fields[2][0] == '\0') {
                spwd.sp_lstchg = -1;
     -  } else if (   (getlong(fields[2], &spwd.sp_lstchg) == -1)
     +  } else if (   (str2sl(&spwd.sp_lstchg, fields[2]) == -1)
                   || (spwd.sp_lstchg < 0)) {
    -           return 0;
    +           return NULL;
        }
    -@@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
    +@@ lib/sgetspent.c: sgetspent(const char *string)
      
        if (fields[3][0] == '\0') {
                spwd.sp_min = -1;
     -  } else if (   (getlong(fields[3], &spwd.sp_min) == -1)
     +  } else if (   (str2sl(&spwd.sp_min, fields[3]) == -1)
                   || (spwd.sp_min < 0)) {
    -           return 0;
    +           return NULL;
        }
    -@@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
    +@@ lib/sgetspent.c: sgetspent(const char *string)
      
        if (fields[4][0] == '\0') {
                spwd.sp_max = -1;
     -  } else if (   (getlong(fields[4], &spwd.sp_max) == -1)
     +  } else if (   (str2sl(&spwd.sp_max, fields[4]) == -1)
                   || (spwd.sp_max < 0)) {
    -           return 0;
    +           return NULL;
        }
    -@@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
    +@@ lib/sgetspent.c: sgetspent(const char *string)
      
        if (fields[5][0] == '\0') {
                spwd.sp_warn = -1;
     -  } else if (   (getlong(fields[5], &spwd.sp_warn) == -1)
     +  } else if (   (str2sl(&spwd.sp_warn, fields[5]) == -1)
                   || (spwd.sp_warn < 0)) {
    -           return 0;
    +           return NULL;
        }
    -@@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
    +@@ lib/sgetspent.c: sgetspent(const char *string)
      
        if (fields[6][0] == '\0') {
                spwd.sp_inact = -1;
     -  } else if (   (getlong(fields[6], &spwd.sp_inact) == -1)
     +  } else if (   (str2sl(&spwd.sp_inact, fields[6]) == -1)
                   || (spwd.sp_inact < 0)) {
    -           return 0;
    +           return NULL;
        }
    -@@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
    +@@ lib/sgetspent.c: sgetspent(const char *string)
      
        if (fields[7][0] == '\0') {
                spwd.sp_expire = -1;
     -  } else if (   (getlong(fields[7], &spwd.sp_expire) == -1)
     +  } else if (   (str2sl(&spwd.sp_expire, fields[7]) == -1)
                   || (spwd.sp_expire < 0)) {
    -           return 0;
    +           return NULL;
        }
    -@@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
    +@@ lib/sgetspent.c: sgetspent(const char *string)
      
        if (fields[8][0] == '\0') {
                spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
     -  } else if (getulong(fields[8], &spwd.sp_flag) == -1) {
     +  } else if (str2ul(&spwd.sp_flag, fields[8]) == -1) {
    -           return 0;
    +           return NULL;
        }
      
    -@@ lib/sgetspent.c: struct spwd *sgetspent (const char *string)
    - #else
    - extern int ISO_C_forbids_an_empty_translation_unit;
    - #endif
    --
     
      ## lib/shadow.c ##
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
        if (fields[2][0] == '\0') {
                spwd.sp_lstchg = -1;
        } else {
    --          if (getlong(fields[2], &spwd.sp_lstchg) == -1) {
    -+          if (str2sl(&spwd.sp_lstchg, fields[2]) == -1) {
    - #ifdef    USE_NIS
    -                   if (nis_used) {
    -                           spwd.sp_lstchg = -1;
    +-          if (getlong(fields[2], &spwd.sp_lstchg) == -1)
    ++          if (str2sl(&spwd.sp_lstchg, fields[2]) == -1)
    +                   return 0;
    +           if (spwd.sp_lstchg < 0)
    +                   return 0;
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
        if (fields[3][0] == '\0') {
                spwd.sp_min = -1;
        } else {
    --          if (getlong(fields[3], &spwd.sp_min) == -1) {
    -+          if (str2sl(&spwd.sp_min, fields[3]) == -1) {
    - #ifdef    USE_NIS
    -                   if (nis_used) {
    -                           spwd.sp_min = -1;
    +-          if (getlong(fields[3], &spwd.sp_min) == -1)
    ++          if (str2sl(&spwd.sp_min, fields[3]) == -1)
    +                   return 0;
    +           if (spwd.sp_min < 0)
    +                   return 0;
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
        if (fields[4][0] == '\0') {
                spwd.sp_max = -1;
        } else {
    --          if (getlong(fields[4], &spwd.sp_max) == -1) {
    -+          if (str2sl(&spwd.sp_max, fields[4]) == -1) {
    - #ifdef    USE_NIS
    -                   if (nis_used) {
    -                           spwd.sp_max = -1;
    +-          if (getlong(fields[4], &spwd.sp_max) == -1)
    ++          if (str2sl(&spwd.sp_max, fields[4]) == -1)
    +                   return 0;
    +           if (spwd.sp_max < 0)
    +                   return 0;
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
        if (fields[5][0] == '\0') {
                spwd.sp_warn = -1;
        } else {
    --          if (getlong(fields[5], &spwd.sp_warn) == -1) {
    -+          if (str2sl(&spwd.sp_warn, fields[5]) == -1) {
    - #ifdef    USE_NIS
    -                   if (nis_used) {
    -                           spwd.sp_warn = -1;
    +-          if (getlong(fields[5], &spwd.sp_warn) == -1)
    ++          if (str2sl(&spwd.sp_warn, fields[5]) == -1)
    +                   return 0;
    +           if (spwd.sp_warn < 0)
    +                   return 0;
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
        if (fields[6][0] == '\0') {
                spwd.sp_inact = -1;
        } else {
    --          if (getlong(fields[6], &spwd.sp_inact) == -1) {
    -+          if (str2sl(&spwd.sp_inact, fields[6]) == -1) {
    - #ifdef    USE_NIS
    -                   if (nis_used) {
    -                           spwd.sp_inact = -1;
    +-          if (getlong(fields[6], &spwd.sp_inact) == -1)
    ++          if (str2sl(&spwd.sp_inact, fields[6]) == -1)
    +                   return 0;
    +           if (spwd.sp_inact < 0)
    +                   return 0;
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
        if (fields[7][0] == '\0') {
                spwd.sp_expire = -1;
        } else {
    --          if (getlong(fields[7], &spwd.sp_expire) == -1) {
    -+          if (str2sl(&spwd.sp_expire, fields[7]) == -1) {
    - #ifdef    USE_NIS
    -                   if (nis_used) {
    -                           spwd.sp_expire = -1;
    +-          if (getlong(fields[7], &spwd.sp_expire) == -1)
    ++          if (str2sl(&spwd.sp_expire, fields[7]) == -1)
    +                   return 0;
    +           if (spwd.sp_expire < 0)
    +                   return 0;
     @@ lib/shadow.c: static struct spwd *my_sgetspent (const char *string)
        if (fields[8][0] == '\0') {
                spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
        } else {
    --          if (getulong(fields[8], &spwd.sp_flag) == -1) {
    -+          if (str2ul(&spwd.sp_flag, fields[8]) == -1) {
    - #ifdef    USE_NIS
    -                   if (nis_used) {
    -                           spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
    +-          if (getulong(fields[8], &spwd.sp_flag) == -1)
    ++          if (str2ul(&spwd.sp_flag, fields[8]) == -1)
    +                   return 0;
    +           if (spwd.sp_flag < 0)
    +                   return 0;
     
      ## lib/strtoday.c ##
     @@ lib/strtoday.c: long strtoday (const char *str)
    @@ lib/strtoday.c: long strtoday (const char *str)
      
     
      ## lib/subordinateio.c ##
    -@@ lib/subordinateio.c: static void *subordinate_parse (const char *line)
    +@@ lib/subordinateio.c: subordinate_parse(const char *line)
        if (i != SUBID_NFIELDS || *fields[0] == '\0' || *fields[1] == '\0' || *fields[2] == '\0')
                return NULL;
        range.owner = fields[0];
4:  3ca0de33 = 4:  a46e9dcc lib/atoi/: a2*(), str2*(): Add variants for other types

@alejandro-colomar alejandro-colomar force-pushed the getlong branch 2 times, most recently from a46e9dc to b4c4311 Compare March 21, 2024 13:37
@alejandro-colomar
Copy link
Collaborator Author

v3b changes:

  • Rebase on master
$ git range-diff gh/master..gh/getlong shadow/master..getlong 
1:  f473ccd7 = 1:  844fcc79 lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
2:  83518d40 = 2:  dd241fba lib/atoi/: Add a2[su]l() and reimplement get[u]long() in terms of them
3:  b3bd3d68 = 3:  b4c5b2a1 lib/, src/: str2*(): Rename functions and reorder parameters
4:  a46e9dcc = 4:  b4c43114 lib/atoi/: a2*(), str2*(): Add variants for other types

And make them inline.

Signed-off-by: Alejandro Colomar <[email protected]>
This makes them compatible with liba2i's functions.

Signed-off-by: Alejandro Colomar <[email protected]>
And type-generic macros that wrap them: a2i(), str2i()

Signed-off-by: Alejandro Colomar <[email protected]>
@alejandro-colomar
Copy link
Collaborator Author

v3c changes:

  • Rebase on master
$ git range-diff gh/master..gh/getlong shadow/master..getlong 
1:  844fcc79 ! 1:  50a2642b lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
    @@ src/chpasswd.c
     
      ## src/faillog.c ##
     @@
    - #include <sys/types.h>
      #include <time.h>
      #include <assert.h>
    -+
    + 
     +#include "atoi/str2i.h"
      #include "defines.h"
      #include "faillog.h"
      #include "memzero.h"
     @@
    - #include "exitcodes.h"
    - #include "shadowlog.h"
    + #include "string/strftime.h"
    + 
      
     +
      /* local function prototypes */
    @@ src/faillog.c
     
      ## src/lastlog.c ##
     @@
    - #ifdef HAVE_LL_HOST
      #include <net/if.h>
      #endif
    -+
    + 
     +#include "atoi/str2i.h"
      #include "defines.h"
      #include "prototypes.h"
      #include "getdef.h"
     @@
    - #include "exitcodes.h"
    - #include "shadowlog.h"
    + #include "string/strftime.h"
    + 
      
     +
      /*
2:  dd241fba = 2:  ea70bfa3 lib/atoi/: Add a2[su]l() and reimplement get[u]long() in terms of them
3:  b4c5b2a1 = 3:  29d01b87 lib/, src/: str2*(): Rename functions and reorder parameters
4:  b4c43114 = 4:  01e906fe lib/atoi/: a2*(), str2*(): Add variants for other types

@hallyn hallyn merged commit f7fe4c5 into shadow-maint:master Mar 29, 2024
9 checks passed
@alejandro-colomar
Copy link
Collaborator Author

Weee! Thanks, @hallyn !

@alejandro-colomar alejandro-colomar deleted the getlong branch March 29, 2024 19:34
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.

2 participants