OUX_User user;The class provides member functions for accessing the commonly used fields kept for a user in the UNIX password file.
cout << user.name() << endl; // login name
cout << user.fullname() << endl; // real name
cout << user.uid() << endl; // user id
cout << user.gid() << endl; // group id
To obtain information about a specific user the constructor can be passed the users login name, their user ID or a passwd file entry. If the information passed to the constructor does not describe a valid user the `isValid()' function will return OTCLIB_FALSE.
OUX_User user("root");To obtain information about a UNIX group, the OUX_Group class is used. To obtain information about the group a process is executing as, the null constructor is used.
if (user.isValid())
...
OUX_Group group;Whether a user is a member of a group can be determined by using the `isMember()' member function.
cout << group.name() << endl; // group name
cout << group.gid() << endl; // group id
OTC_Iterator<OTC_String> iter; // group members
iter = group.members();
for (iter.reset(); iter.isValid(); iter.next())
cout << iter.item() << endl;
if (group.isMember("root"))Information about a particular group can be obtained by passing the constructor either a group name, group ID or a group file entry. The `isValid()' member function will return OTCLIB_TRUE if the constructor arguments described a valid group.
...
Note that on some variants of UNIX, use of OUX_User and OUX_Group will result in the status of the system functions `getpwent()' and `getgrent()' being changed. Therefore, avoid using these system functions to consult successive entries in the passwd and group files at the same time as using the OUX_User and OUX_Group classes.
To use the class the list of signals to be blocked is passed to the constructor as a bit mask. If no argument is passed to the constructor, all signals which can be blocked, are blocked. The signals are unblocked when the instance of the OUX_SignalBlock class is destroyed.
if (...)
{
OUX_SignalBlock block(SIGUSR1|SIGUSR2);
...
}