group |
Each security group has a unique
identifier with associated information, such as a name and a domain. This
information is usually stored in an operating system database, such as
/etc/group or the Network Information Service (NIS) in UNIX, or the Security
Account Manager (SAM) in Windows NT. The os_group
class provides a portable method for accessing and manipulating this
information.
The following example demonstrates
the os_group class on a UNIX system.
#include <iostream>
#include <ospace/security.h>
void
main()
{
os_security_toolkit initialize;
// Construct to reference group "cavemen".
os_group group1( string( "cavemen" ) );
// Construct group2 to reference group with GID 1.
os_group group2( 1 );
cout << "group1 = " << group1 << end1;
cout << "group2 = " << group2 << end1;
cout << group1 << " == " << group2 << " = ";
cout << (group1 == group2) << endl;
cout << group1 << " == " << group1 << " = ";
cout << (group1 == group1) << endl;
}
group1 = os_group( cavemen, 21 )
group2 = os_group( daemon, 1 )
os_group( cavemen, 21 ) == os_group( daemon, 1 ) = 0
os_group( cavemen, 21 ) == os_group( cavemen, 21 ) = 1
On UNIX systems, you can list
the users that belong to a group by using users()
. In addition, you can use the static function groups()
to obtain a list of all groups in the system, as shown in the following
example.
#include <iostream>
#include <ospace/security.h>
void
main()
{
os_security_toolkit initialize;
os_group group( "cavemen" );
vector< uid_t > users = group.users();
cout << group << " has the following users: " << endl;
vector< uid_t >::iterator i;
for ( i = users.begin(); i != users.end(); i++ )
cout << " " << os_user( *i ) << endl;
cout << endl;
vector< gid_t > groups = os_group::groups();
cout << "List of all the groups in the group database:" << endl;
vector< gid_t >::iterator j;
for ( j = groups.begin(); j != groups.end(); j++ )
cout << " " << os_group( *j ) << endl;
}
os_group( cavemen, 21 ) has the following users:
os_user( ned, 101 )
os_user( fred, 100 )
...
os_user( sysrel, 136 )
List of all groups in the group database:
os_group( wheel, 0 )
os_group( cavemen, 21 )
...
os_group( daemon, 1 )
The next example, executed on a Windows NT workstation, returns the domain information for a particular group.
#include <iostream>
#include <ospace/security.h>
void
main()
{
os_security_toolkit initialize;
os_group group( "Technical" );
cout
<< "Group \'" << group.name()
<< "\' belongs to the domain \'"<< group.domain()
<< "\'." << endl;
}
Group 'Technical' belongs to the domain 'OBJSPACE'.
Refer to the dir4.cpp example in
File<ToolKit> for a more complex example that
uses both os_group and os_user
.
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.