Changeset View
Changeset View
Standalone View
Standalone View
head/usr.bin/users/users.cc
Show All 21 Lines | |||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/capsicum.h> | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <err.h> | |||||
#include <errno.h> | |||||
#include <utmpx.h> | #include <utmpx.h> | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <iostream> | #include <iostream> | ||||
#include <iterator> | #include <iterator> | ||||
#include <set> | #include <set> | ||||
#include <string> | #include <string> | ||||
using namespace std; | using namespace std; | ||||
int | int | ||||
main(int argc, char **) | main(int argc, char **) | ||||
{ | { | ||||
struct utmpx *ut; | struct utmpx *ut; | ||||
set<string> names; | set<string> names; | ||||
if (argc > 1) { | if (argc > 1) { | ||||
cerr << "usage: users" << endl; | cerr << "usage: users" << endl; | ||||
return (1); | return (1); | ||||
} | } | ||||
setutxent(); | setutxent(); | ||||
if (cap_enter() < 0 && errno != ENOSYS) | |||||
err(1, "Failed to enter capability mode."); | |||||
while ((ut = getutxent()) != NULL) | while ((ut = getutxent()) != NULL) | ||||
if (ut->ut_type == USER_PROCESS) | if (ut->ut_type == USER_PROCESS) | ||||
names.insert(ut->ut_user); | names.insert(ut->ut_user); | ||||
endutxent(); | endutxent(); | ||||
if (!names.empty()) { | if (!names.empty()) { | ||||
set<string>::iterator last = names.end(); | set<string>::iterator last = names.end(); | ||||
--last; | --last; | ||||
copy(names.begin(), last, ostream_iterator<string>(cout, " ")); | copy(names.begin(), last, ostream_iterator<string>(cout, " ")); | ||||
cout << *last << endl; | cout << *last << endl; | ||||
} | } | ||||
} | } |