{
u8 *chroot_path;
int uid, gid, rv;
- char *s, buf[128];
+ const int max_buf_size = 4096;
+ char *s, *buf;
struct passwd _pw, *pw;
struct group _grp, *grp;
clib_error_t *e;
-
+ buf = vec_new(char,128);
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, "prefix %s", &chroot_path))
{
/* lookup the username */
pw = NULL;
- rv = getpwnam_r (s, &_pw, buf, sizeof (buf), &pw);
+ while (((rv = getpwnam_r (s, &_pw, buf, sizeof (buf), &pw)) == ERANGE) && ( vec_len(buf) <= max_buf_size ))
+ {
+ vec_resize(buf,vec_len(buf)*2);
+ }
if (rv < 0)
{
e = clib_error_return_code (0, rv,
CLIB_ERROR_FATAL,
"cannot fetch username %s", s);
vec_free (s);
+ vec_free (buf);
return e;
}
if (pw == NULL)
e =
clib_error_return_fatal (0, "username %s does not exist", s);
vec_free (s);
+ vec_free (buf);
return e;
}
vec_free (s);
{
/* lookup the group name */
grp = NULL;
- rv = getgrnam_r (s, &_grp, buf, sizeof (buf), &grp);
+ while ( ( (rv = getgrnam_r (s, &_grp, buf, vec_len(buf), &grp)) == ERANGE ) && ( vec_len(buf) <= max_buf_size ) )
+ {
+ vec_resize(buf,vec_len(buf)*2);
+ }
if (rv != 0)
{
e = clib_error_return_code (0, rv,
CLIB_ERROR_FATAL,
"cannot fetch group %s", s);
vec_free (s);
+ vec_free (buf);
return e;
}
if (grp == NULL)
{
e = clib_error_return_fatal (0, "group %s does not exist", s);
vec_free (s);
+ vec_free (buf);
return e;
}
vec_free (s);
+ vec_free (buf);
vl_set_memory_gid (grp->gr_gid);
}
else