#91 Trouble with getpwent()

open
nobody
None
5
2012-10-25
2012-10-25
Orion Poplawski
No

Running repquota -a on a system using sssd, users not in /etc/passwd will not be resolved by default. This is because sssd will not enumerate a full list of users by default (as with very large user databases this may be a very expensive operation) and getpwent() will not list them. Better would be to lookup user ids with getpwuid(). Same issue with groups.

Discussion

1 2 > >> (Page 1 of 2)
  • Jan Kara
    Jan Kara
    2012-11-06

    Yes, I'm aware of this. The problem with getpwuid() is that you have to get the uid from somewhere. And doing for (i = 0; i < 0xffffffff; i++) { user = getpwuid(i); ... } won't quite cut it either... Really the right solution for this is to provide a kernel interface to dump all known quota structures to userspace.

    And yes, I'm guilty for not implementing such an interface for quite a long time :(.

     
  • Perhaps I'm not reading things correctly, but in repquota.c dump_cached_dquots(), it looks like you already have all of the quota entries in dquot_cache[]. Couldn't you just loop through that (as done at the end to pick up unknown users/groups) and do a getpwuid(dquot_cache[i].dq_id) for each entry? It changes the sort order of the output from /etc/passwd order to dquot_cache order, but I imagine you could even sort that array on uid if desired.

     
  • Jan Kara
    Jan Kara
    2012-11-08

    Now I see what you are pointing at. OK, so that particular code could be changed to use getpwuid(). It's just that with plain old /etc/passwd what we do is faster (that's why I ended up implementing cached uid->name translation after all). Also this code is not executed for every filesystem. XFS, ocfs2, or ext4 (just recently) do not have quota files available to userspace applications and thus repquota has to be implemented by iterating over all users and querying kernel for quota information. So for those filesystems we have to use getpwent().

     
  • Simply want to say your article is as astonishing. The clarity in your post is simply cool and i can assume youre an expert on this subject. Well with your permission allow me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please continue the enjoyable work.
    <a href="http://high-quality-katy-perry-dresses86.onsugar.com/" title="For the greatest">For the greatest</a>

     
  • How have you ever help make your blog look this cool. Email me in case you possibly can and reveal your intelligence. Id end up being appreciative!
    <a href="http://games.darbhanga.net/index.php?params=profile/view/9132/" title="Beverage">Beverage</a>

     
1 2 > >> (Page 1 of 2)


Anonymous


Cancel   Add attachments