* strings.h (strechr): New function.
* uinfo.cc (pwdgrp::next_str): Search only for input char in string. Return EOS on failure. Don't check for NULL since it shouldn't be possible. (pwdgrp::add_line): Revert to replacing '\n' in input line with '\0'. (pwdgrp::next_num): Pass explicit separator character to next_str. * grp.cc (pwdgrp::parse_group): Ditto. * passwd.cc (pwdgrp::parse_passwd): Ditto. Revamp test for garbage input. * pwdgrp.h (pwdgrp::next_str): Don't use default parameter.
This commit is contained in:
parent
285d6b97b1
commit
fea48988ea
@ -1,3 +1,16 @@
|
|||||||
|
2003-01-26 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
|
* strings.h (strechr): New function.
|
||||||
|
* uinfo.cc (pwdgrp::next_str): Search only for input char in string.
|
||||||
|
Return EOS on failure. Don't check for NULL since it shouldn't be
|
||||||
|
possible.
|
||||||
|
(pwdgrp::add_line): Revert to replacing '\n' in input line with '\0'.
|
||||||
|
(pwdgrp::next_num): Pass explicit separator character to next_str.
|
||||||
|
* grp.cc (pwdgrp::parse_group): Ditto.
|
||||||
|
* passwd.cc (pwdgrp::parse_passwd): Ditto. Revamp test for garbage
|
||||||
|
input.
|
||||||
|
* pwdgrp.h (pwdgrp::next_str): Don't use default parameter.
|
||||||
|
|
||||||
2003-01-26 Christopher Faylor <cgf@redhat.com>
|
2003-01-26 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* uinfo.cc (pwdgrp::load): Regularize strace output. Add warning for
|
* uinfo.cc (pwdgrp::load): Regularize strace output. Add warning for
|
||||||
|
@ -37,11 +37,11 @@ bool
|
|||||||
pwdgrp::parse_group ()
|
pwdgrp::parse_group ()
|
||||||
{
|
{
|
||||||
# define grp (*group_buf)[curr_lines]
|
# define grp (*group_buf)[curr_lines]
|
||||||
grp.gr_name = next_str ();
|
grp.gr_name = next_str (':');
|
||||||
if (!*grp.gr_name)
|
if (!*grp.gr_name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
grp.gr_passwd = next_str ();
|
grp.gr_passwd = next_str (':');
|
||||||
|
|
||||||
if (!next_num (grp.gr_gid))
|
if (!next_num (grp.gr_gid))
|
||||||
return false;
|
return false;
|
||||||
|
@ -38,18 +38,17 @@ bool
|
|||||||
pwdgrp::parse_passwd ()
|
pwdgrp::parse_passwd ()
|
||||||
{
|
{
|
||||||
# define res (*passwd_buf)[curr_lines]
|
# define res (*passwd_buf)[curr_lines]
|
||||||
res.pw_name = next_str ();
|
res.pw_name = next_str (':');
|
||||||
res.pw_passwd = next_str ();
|
res.pw_passwd = next_str (':');
|
||||||
|
char *p = raw_ptr ();
|
||||||
if (res.pw_name == res.pw_passwd)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
(void) next_num (res.pw_uid);
|
(void) next_num (res.pw_uid);
|
||||||
|
if (p == raw_ptr ())
|
||||||
|
return false; /* parsing did not advance. line is garbage */
|
||||||
(void) next_num (res.pw_gid);
|
(void) next_num (res.pw_gid);
|
||||||
res.pw_comment = NULL;
|
res.pw_comment = NULL;
|
||||||
res.pw_gecos = next_str ();
|
res.pw_gecos = next_str (':');
|
||||||
res.pw_dir = next_str ();
|
res.pw_dir = next_str (':');
|
||||||
res.pw_shell = next_str ();
|
res.pw_shell = next_str (':');
|
||||||
return true;
|
return true;
|
||||||
# undef res
|
# undef res
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class pwdgrp
|
|||||||
void read_group ();
|
void read_group ();
|
||||||
char *add_line (char *);
|
char *add_line (char *);
|
||||||
char *raw_ptr () const {return lptr;}
|
char *raw_ptr () const {return lptr;}
|
||||||
char *next_str (char = 0);
|
char *next_str (char);
|
||||||
bool next_num (unsigned long&);
|
bool next_num (unsigned long&);
|
||||||
bool next_num (unsigned int& i)
|
bool next_num (unsigned int& i)
|
||||||
{
|
{
|
||||||
|
@ -38,6 +38,27 @@ strchr (const char *s, int c)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef strechr
|
||||||
|
#define strechr cygwin_strechr
|
||||||
|
static inline __stdcall char *
|
||||||
|
strechr (const char *s, int c)
|
||||||
|
{
|
||||||
|
register char * res;
|
||||||
|
__asm__ __volatile__ ("\
|
||||||
|
movb %%al,%%ah\n\
|
||||||
|
1: movb (%1),%%al\n\
|
||||||
|
cmpb %%ah,%%al\n\
|
||||||
|
je 2f\n\
|
||||||
|
incl %1\n\
|
||||||
|
testb %%al,%%al\n\
|
||||||
|
jne 1b\n\
|
||||||
|
decl %1\n\
|
||||||
|
2: movl %1,%0\n\
|
||||||
|
":"=a" (res), "=r" (s)
|
||||||
|
:"0" (c), "1" (s));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
extern const char isalpha_array[];
|
extern const char isalpha_array[];
|
||||||
|
|
||||||
#undef strcasematch
|
#undef strcasematch
|
||||||
|
@ -394,24 +394,17 @@ cygheap_user::env_name (const char *name, size_t namelen)
|
|||||||
char *
|
char *
|
||||||
pwdgrp::next_str (char c)
|
pwdgrp::next_str (char c)
|
||||||
{
|
{
|
||||||
if (!lptr)
|
|
||||||
return NULL;
|
|
||||||
char search[] = ":\n\0\0";
|
|
||||||
search[2] = c;
|
|
||||||
char *res = lptr;
|
char *res = lptr;
|
||||||
char *p = strpbrk (lptr, search);
|
lptr = strechr (lptr, c);
|
||||||
if (p)
|
if (*lptr)
|
||||||
{
|
*lptr++ = '\0';
|
||||||
lptr = (*p == '\n') ? p : p + 1;
|
|
||||||
*p = '\0';
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pwdgrp::next_num (unsigned long& n)
|
pwdgrp::next_num (unsigned long& n)
|
||||||
{
|
{
|
||||||
char *p = next_str ();
|
char *p = next_str (':');
|
||||||
if (!p)
|
if (!p)
|
||||||
return -1;
|
return -1;
|
||||||
char *cp;
|
char *cp;
|
||||||
@ -425,11 +418,13 @@ pwdgrp::add_line (char *eptr)
|
|||||||
if (eptr)
|
if (eptr)
|
||||||
{
|
{
|
||||||
lptr = eptr;
|
lptr = eptr;
|
||||||
eptr = strchr (lptr, '\n');
|
eptr = strechr (lptr, '\n');
|
||||||
if (eptr)
|
if (*eptr)
|
||||||
{
|
{
|
||||||
if (eptr > lptr && eptr[-1] == '\r')
|
if (eptr > lptr && eptr[-1] == '\r')
|
||||||
eptr[-1] = '\n';
|
eptr[-1] = '\0';
|
||||||
|
else
|
||||||
|
*eptr = '\0';
|
||||||
eptr++;
|
eptr++;
|
||||||
}
|
}
|
||||||
if (curr_lines >= max_lines)
|
if (curr_lines >= max_lines)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user