version 1.1, 2012/02/21 16:23:02
|
version 1.1.1.2, 2012/05/29 12:26:49
|
Line 48
|
Line 48
|
# include <malloc.h> |
# include <malloc.h> |
#endif /* HAVE_MALLOC_H && !STDC_HEADERS */ |
#endif /* HAVE_MALLOC_H && !STDC_HEADERS */ |
#include <ctype.h> |
#include <ctype.h> |
|
|
#include "sudoers.h" |
#include "sudoers.h" |
#include "parse.h" |
#include "parse.h" |
#include "toke.h" |
#include "toke.h" |
Line 56
|
Line 57
|
static int arg_len = 0; |
static int arg_len = 0; |
static int arg_size = 0; |
static int arg_size = 0; |
|
|
static unsigned char | static int |
hexchar(const char *s) |
hexchar(const char *s) |
{ |
{ |
int i; | int i, result = 0; |
int result = 0; | debug_decl(hexchar, SUDO_DEBUG_PARSER) |
|
|
s += 2; /* skip \\x */ |
s += 2; /* skip \\x */ |
for (i = 0; i < 2; i++) { |
for (i = 0; i < 2; i++) { |
Line 98 hexchar(const char *s)
|
Line 99 hexchar(const char *s)
|
s++; |
s++; |
} |
} |
} |
} |
return (unsigned char)result; | debug_return_int(result); |
} |
} |
|
|
int | bool |
fill_txt(const char *src, int len, int olen) |
fill_txt(const char *src, int len, int olen) |
{ |
{ |
char *dst; |
char *dst; |
|
debug_decl(fill_txt, SUDO_DEBUG_PARSER) |
|
|
dst = olen ? realloc(yylval.string, olen + len + 1) : malloc(len + 1); |
dst = olen ? realloc(yylval.string, olen + len + 1) : malloc(len + 1); |
if (dst == NULL) { |
if (dst == NULL) { |
yyerror(_("unable to allocate memory")); |
yyerror(_("unable to allocate memory")); |
return FALSE; | debug_return_bool(false); |
} |
} |
yylval.string = dst; |
yylval.string = dst; |
|
|
Line 133 fill_txt(const char *src, int len, int olen)
|
Line 135 fill_txt(const char *src, int len, int olen)
|
} |
} |
} |
} |
*dst = '\0'; |
*dst = '\0'; |
return TRUE; | debug_return_bool(true); |
} |
} |
|
|
int | bool |
append(const char *src, int len) |
append(const char *src, int len) |
{ |
{ |
int olen = 0; |
int olen = 0; |
|
debug_decl(append, SUDO_DEBUG_PARSER) |
|
|
if (yylval.string != NULL) |
if (yylval.string != NULL) |
olen = strlen(yylval.string); |
olen = strlen(yylval.string); |
|
|
return fill_txt(src, len, olen); | debug_return_bool(fill_txt(src, len, olen)); |
} |
} |
|
|
#define SPECIAL(c) \ |
#define SPECIAL(c) \ |
((c) == ',' || (c) == ':' || (c) == '=' || (c) == ' ' || (c) == '\t' || (c) == '#') |
((c) == ',' || (c) == ':' || (c) == '=' || (c) == ' ' || (c) == '\t' || (c) == '#') |
|
|
int | bool |
fill_cmnd(const char *src, int len) |
fill_cmnd(const char *src, int len) |
{ |
{ |
char *dst; |
char *dst; |
int i; |
int i; |
|
debug_decl(fill_cmnd, SUDO_DEBUG_PARSER) |
|
|
arg_len = arg_size = 0; |
arg_len = arg_size = 0; |
|
|
dst = yylval.command.cmnd = (char *) malloc(len + 1); |
dst = yylval.command.cmnd = (char *) malloc(len + 1); |
if (yylval.command.cmnd == NULL) { |
if (yylval.command.cmnd == NULL) { |
yyerror(_("unable to allocate memory")); |
yyerror(_("unable to allocate memory")); |
return FALSE; | debug_return_bool(false); |
} |
} |
|
|
/* Copy the string and collapse any escaped sudo-specific characters. */ |
/* Copy the string and collapse any escaped sudo-specific characters. */ |
Line 174 fill_cmnd(const char *src, int len)
|
Line 178 fill_cmnd(const char *src, int len)
|
*dst = '\0'; |
*dst = '\0'; |
|
|
yylval.command.args = NULL; |
yylval.command.args = NULL; |
return TRUE; | debug_return_bool(true); |
} |
} |
|
|
int | bool |
fill_args(const char *s, int len, int addspace) |
fill_args(const char *s, int len, int addspace) |
{ |
{ |
int new_len; |
int new_len; |
char *p; |
char *p; |
|
debug_decl(fill_args, SUDO_DEBUG_PARSER) |
|
|
if (yylval.command.args == NULL) { |
if (yylval.command.args == NULL) { |
addspace = 0; |
addspace = 0; |
Line 200 fill_args(const char *s, int len, int addspace)
|
Line 205 fill_args(const char *s, int len, int addspace)
|
if (p == NULL) { |
if (p == NULL) { |
efree(yylval.command.args); |
efree(yylval.command.args); |
yyerror(_("unable to allocate memory")); |
yyerror(_("unable to allocate memory")); |
return FALSE; | debug_return_bool(false); |
} else |
} else |
yylval.command.args = p; |
yylval.command.args = p; |
} |
} |
Line 211 fill_args(const char *s, int len, int addspace)
|
Line 216 fill_args(const char *s, int len, int addspace)
|
*p++ = ' '; |
*p++ = ' '; |
if (strlcpy(p, s, arg_size - (p - yylval.command.args)) != len) { |
if (strlcpy(p, s, arg_size - (p - yylval.command.args)) != len) { |
yyerror(_("fill_args: buffer overflow")); /* paranoia */ |
yyerror(_("fill_args: buffer overflow")); /* paranoia */ |
return FALSE; | debug_return_bool(false); |
} |
} |
arg_len = new_len; |
arg_len = new_len; |
return TRUE; | debug_return_bool(true); |
} |
} |
|
|
/* |
/* |
* Check to make sure an IPv6 address does not contain multiple instances |
* Check to make sure an IPv6 address does not contain multiple instances |
* of the string "::". Assumes strlen(s) >= 1. |
* of the string "::". Assumes strlen(s) >= 1. |
* Returns TRUE if address is valid else FALSE. | * Returns true if address is valid else false. |
*/ |
*/ |
int | bool |
ipv6_valid(const char *s) |
ipv6_valid(const char *s) |
{ |
{ |
int nmatch = 0; |
int nmatch = 0; |
|
debug_decl(ipv6_valid, SUDO_DEBUG_PARSER) |
|
|
for (; *s != '\0'; s++) { |
for (; *s != '\0'; s++) { |
if (s[0] == ':' && s[1] == ':') { |
if (s[0] == ':' && s[1] == ':') { |
Line 236 ipv6_valid(const char *s)
|
Line 242 ipv6_valid(const char *s)
|
nmatch = 0; /* reset if we hit netmask */ |
nmatch = 0; /* reset if we hit netmask */ |
} |
} |
|
|
return nmatch <= 1; | debug_return_bool(nmatch <= 1); |
} |
} |