#include <pwd.h>
#include <grp.h>
#include "myuser.h"
//fake class to implement only one function

QString MyUser::loginName(pid_t pid)
{
  struct passwd * pw = getpwuid(pid?pid:getuid());
  if (pw) return QString::fromLocal8Bit(pw->pw_name);
  return QString::null;
}

QString MyUser::rootLoginName()
{
  struct passwd * pw = getpwuid(0);
  if (pw) return QString::fromLocal8Bit(pw->pw_name);
  return QString::null;
}

unsigned int MyUser::groupMemberNum(const QString& groupName)
{
    unsigned int i=0;
    struct group * gr = getgrnam(groupName.toLocal8Bit().data());
    if (gr)
    {
      for (i=0; gr->gr_mem[i]; i++);
    }
    return i;
}


QString MyUser::groupMember(const QString& groupName, unsigned int ind)
{
  struct group * gr = getgrnam(groupName.toLocal8Bit().data());
  if (gr)
  {
    for (unsigned int i=0; gr->gr_mem[i]; i++)
    {
      char *member = gr->gr_mem[i];
      if (i==ind) return QString::fromLocal8Bit((const char *)member);
    }
  }
  return QString::null;
}

