* lib/getdef.c: Use getlong instead of strtol/strtoul.
* libmisc/getlong, lib/getlong.c, libmisc/Makefile.am, lib/Makefile.am: getlong.c moved from libmisc/ to lib/.
This commit is contained in:
parent
1c97cf5c83
commit
84f5ca951c
@ -1,3 +1,9 @@
|
|||||||
|
2009-04-06 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
|
* lib/getdef.c: Use getlong instead of strtol/strtoul.
|
||||||
|
* libmisc/getlong, lib/getlong.c, libmisc/Makefile.am,
|
||||||
|
lib/Makefile.am: getlong.c moved from libmisc/ to lib/.
|
||||||
|
|
||||||
2009-04-06 Nicolas François <nicolas.francois@centraliens.net>
|
2009-04-06 Nicolas François <nicolas.francois@centraliens.net>
|
||||||
|
|
||||||
* lib/shadow.c: Replace strtol() by getlong(). Also detect more
|
* lib/shadow.c: Replace strtol() by getlong(). Also detect more
|
||||||
|
@ -18,6 +18,7 @@ libshadow_la_SOURCES = \
|
|||||||
getdef.c \
|
getdef.c \
|
||||||
getdef.h \
|
getdef.h \
|
||||||
get_gid.c \
|
get_gid.c \
|
||||||
|
getlong.c \
|
||||||
get_uid.c \
|
get_uid.c \
|
||||||
groupio.c \
|
groupio.c \
|
||||||
groupmem.c \
|
groupmem.c \
|
||||||
|
54
lib/getdef.c
54
lib/getdef.c
@ -193,6 +193,7 @@ bool getdef_bool (const char *item)
|
|||||||
int getdef_num (const char *item, int dflt)
|
int getdef_num (const char *item, int dflt)
|
||||||
{
|
{
|
||||||
struct itemdef *d;
|
struct itemdef *d;
|
||||||
|
long val;
|
||||||
|
|
||||||
if (!def_loaded) {
|
if (!def_loaded) {
|
||||||
def_load ();
|
def_load ();
|
||||||
@ -203,8 +204,16 @@ int getdef_num (const char *item, int dflt)
|
|||||||
return dflt;
|
return dflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) strtol (d->value, (char **) NULL, 0);
|
if ( (getlong (d->value, &val) == 0)
|
||||||
/* TODO: check for errors */
|
|| (val > INT_MAX)
|
||||||
|
|| (val < INT_MIN)) {
|
||||||
|
fprintf (stderr,
|
||||||
|
_("configuration error - cannot parse %s value: '%s'"),
|
||||||
|
item, d->value);
|
||||||
|
return dflt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -219,6 +228,7 @@ int getdef_num (const char *item, int dflt)
|
|||||||
unsigned int getdef_unum (const char *item, unsigned int dflt)
|
unsigned int getdef_unum (const char *item, unsigned int dflt)
|
||||||
{
|
{
|
||||||
struct itemdef *d;
|
struct itemdef *d;
|
||||||
|
long val;
|
||||||
|
|
||||||
if (!def_loaded) {
|
if (!def_loaded) {
|
||||||
def_load ();
|
def_load ();
|
||||||
@ -229,8 +239,16 @@ unsigned int getdef_unum (const char *item, unsigned int dflt)
|
|||||||
return dflt;
|
return dflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (unsigned int) strtoul (d->value, (char **) NULL, 0);
|
if ( (getlong (d->value, &val) == 0)
|
||||||
/* TODO: check for errors */
|
|| (val < 0)
|
||||||
|
|| (val > INT_MAX)) {
|
||||||
|
fprintf (stderr,
|
||||||
|
_("configuration error - cannot parse %s value: '%s'"),
|
||||||
|
item, d->value);
|
||||||
|
return dflt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (unsigned int) val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -245,6 +263,7 @@ unsigned int getdef_unum (const char *item, unsigned int dflt)
|
|||||||
long getdef_long (const char *item, long dflt)
|
long getdef_long (const char *item, long dflt)
|
||||||
{
|
{
|
||||||
struct itemdef *d;
|
struct itemdef *d;
|
||||||
|
long val;
|
||||||
|
|
||||||
if (!def_loaded) {
|
if (!def_loaded) {
|
||||||
def_load ();
|
def_load ();
|
||||||
@ -255,8 +274,14 @@ long getdef_long (const char *item, long dflt)
|
|||||||
return dflt;
|
return dflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strtol (d->value, (char **) NULL, 0);
|
if (getlong (d->value, &val) == 0) {
|
||||||
/* TODO: check for errors */
|
fprintf (stderr,
|
||||||
|
_("configuration error - cannot parse %s value: '%s'"),
|
||||||
|
item, d->value);
|
||||||
|
return dflt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -270,6 +295,7 @@ long getdef_long (const char *item, long dflt)
|
|||||||
unsigned long getdef_ulong (const char *item, unsigned long dflt)
|
unsigned long getdef_ulong (const char *item, unsigned long dflt)
|
||||||
{
|
{
|
||||||
struct itemdef *d;
|
struct itemdef *d;
|
||||||
|
long val;
|
||||||
|
|
||||||
if (!def_loaded) {
|
if (!def_loaded) {
|
||||||
def_load ();
|
def_load ();
|
||||||
@ -280,8 +306,15 @@ unsigned long getdef_ulong (const char *item, unsigned long dflt)
|
|||||||
return dflt;
|
return dflt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (unsigned long) strtoul (d->value, (char **) NULL, 0);
|
if (getlong (d->value, &val) == 0) {
|
||||||
/* TODO: check for errors */
|
/* FIXME: we should have a getulong */
|
||||||
|
fprintf (stderr,
|
||||||
|
_("configuration error - cannot parse %s value: '%s'"),
|
||||||
|
item, d->value);
|
||||||
|
return dflt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -354,9 +387,8 @@ static struct itemdef *def_find (const char *name)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_
|
_("configuration error - unknown item '%s' (notify administrator)\n"),
|
||||||
("configuration error - unknown item '%s' (notify administrator)\n"),
|
name);
|
||||||
name);
|
|
||||||
SYSLOG ((LOG_CRIT, "unknown configuration item `%s'", name));
|
SYSLOG ((LOG_CRIT, "unknown configuration item `%s'", name));
|
||||||
return (struct itemdef *) NULL;
|
return (struct itemdef *) NULL;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ libmisc_a_SOURCES = \
|
|||||||
getdate.h \
|
getdate.h \
|
||||||
getdate.y \
|
getdate.y \
|
||||||
getgr_nam_gid.c \
|
getgr_nam_gid.c \
|
||||||
getlong.c \
|
|
||||||
getrange.c \
|
getrange.c \
|
||||||
hushed.c \
|
hushed.c \
|
||||||
isexpired.c \
|
isexpired.c \
|
||||||
|
Loading…
Reference in New Issue
Block a user