[libvirt] [PATCH][take2][1/2] add virGetUIDByUsername() and virGetGIDByGroupname()

Ryota Ozaki ozaki.ryota at gmail.com
Thu Apr 16 15:16:30 UTC 2009


Hi Guido and Daniel,

On Fri, Apr 17, 2009 at 12:07 AM, Guido Günther <agx at sigxcpu.org> wrote:
> Hi Ryota,
> On Thu, Apr 16, 2009 at 11:24:10PM +0900, Ryota Ozaki wrote:
>> +#ifdef HAVE_GETPWNAM_R
>> +int virGetUIDByUsername(virConnectPtr conn, char *name)
>> +{
>> +    struct passwd pwbuf;
>> +    struct passwd *pw = NULL;
>> +    char *strbuf;
>> +    size_t strbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
>
>> +
>> +    if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
>> +        virReportOOMError(conn);
>> +        return -1;
>> +    }
> We should take the same safety measures as in remoteReadConfig file
> here.
>
>> +    if (getpwnam_r(name, &pwbuf, strbuf, strbuflen, &pw) != 0 || pw == NULL) {
>> +        virReportSystemError(conn, errno,
>> +                             _("Failed to find user record for name '%s'"),
>> +                             name);
>> +        VIR_FREE(strbuf);
>> +        return -1;
>> +    }
>> +    VIR_FREE(strbuf);
>> +    return pw->pw_uid;
>> +}
>> +#endif
>> +
>> +
>> +#ifdef HAVE_GETGRNAM_R
>> +int virGetGIDByGroupname(virConnectPtr conn, char *name)
>> +{
>> +    struct group grbuf;
>> +    struct group *gr = NULL;
>> +    char *strbuf;
>> +    size_t strbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
>> +
>> +    if (VIR_ALLOC_N(strbuf, strbuflen) < 0) {
>> +        virReportOOMError(conn);
>> +        return -1;
>> +    }
> same here.
> Cheers,
>  -- Guido
>

Thanks for pointing out. I will fix them.

BTW, do you think the fix should be applied for virGetUserDirectory()
in util.c as well?

Anyway, I will resend a modified patch including Guido's fix.

Thanks!
  ozaki-r




More information about the libvir-list mailing list