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, 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.

Cheers,

-- Slavi

[0] http://man7.org/linux/man-pages/man3/getpwent.3.html



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

  Powered by Linux