Re: [PATCH] kernel-shark: Retrieve the home of root from "/etc/passwd"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 28 Nov 2019 16:27:11 +0200
Slavomir Kaslev <slavomir.kaslev@xxxxxxxxx> wrote:

> On Thu, Nov 28, 2019 at 1:46 PM Yordan Karadzhov (VMware)
> <y.karadz@xxxxxxxxx> wrote:
> [...]
> > +       auto lamRootHome = [] () {
> > +               QFile fPswd("/etc/passwd");
> > +               QString home("/root");
> > +               QStringList userInfo;
> > +
> > +               fPswd.open(QIODevice::ReadOnly);
> > +               if (!fPswd.isOpen())
> > +                       return home;
> > +
> > +               QTextStream s(&fPswd);
> > +               while (!s.atEnd()) {
> > +                       userInfo = s.readLine().split(':');
> > +
> > +                       /* Check the User Id. */
> > +                       if (userInfo[2].toInt() == 0) {
> > +                               home = userInfo[5];
> > +                               break;
> > +                       }
> > +               }
> > +  
> 
> Another option is to use getpwent(3) [0] instead of parsing /etc/passwd by hand.

Thank you! My google fu is starting to show its age, as I did a bit of
searching looking for a library function to parse passwd, knowing one had
to be there, but came up empty. This is exactly what I was looking for.

Yes, Yordan, I think using this would be the better option as if I had
found it, it would have been what I would have suggested in the first
place.

-- Steve



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux