2008-10-08 14:05:00 -04:00
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax io.streams.string kernel quotations sequences strings math ;
IN: unix.users
HELP: all-users
2008-11-05 05:27:12 -05:00
{ $values { "seq" sequence } }
2008-10-08 14:05:00 -04:00
{ $description "Returns a sequence of high-level " { $link passwd } " tuples that are platform-dependent and field for field complete with the Unix " { $link passwd } " structure." } ;
2009-01-07 15:53:43 -05:00
HELP: effective-user-name
2008-11-05 05:27:12 -05:00
{ $values { "string" string } }
2009-01-07 15:53:43 -05:00
{ $description "Returns the effective user-name for the current user." } ;
2008-10-08 14:05:00 -04:00
2008-10-08 14:22:53 -04:00
HELP: effective-user-id
2008-11-05 05:27:12 -05:00
{ $values { "id" integer } }
2009-01-07 15:53:43 -05:00
{ $description "Returns the effective user-name id for the current user." } ;
2008-10-08 14:05:00 -04:00
HELP: new-passwd
2008-11-05 05:27:12 -05:00
{ $values { "passwd" passwd } }
2008-10-08 14:05:00 -04:00
{ $description "Creates a new passwd tuple dependent on the operating system." } ;
HELP: passwd
{ $description "A platform-specific tuple correspding to every field from the Unix passwd struct. BSD passwd structures have four extra slots: " { $slot "change" } ", " { $slot "class" } "," { $slot "expire" } ", " { $slot "fields" } "." } ;
2008-11-11 14:05:04 -05:00
HELP: user-cache
{ $description "A symbol storing passwd structures indexed by user-ids when within a " { $link with-user-cache } "." } ;
2008-10-08 14:05:00 -04:00
HELP: passwd>new-passwd
{ $values
{ "passwd" "a passwd struct" }
{ "new-passwd" "a passwd tuple" } }
{ $description "A platform-specific conversion routine from a passwd structure to a passwd tuple." } ;
2009-01-07 15:53:43 -05:00
HELP: real-user-name
2008-11-05 05:27:12 -05:00
{ $values { "string" string } }
2009-01-07 15:53:43 -05:00
{ $description "The real user-name of the current user." } ;
2008-10-08 14:05:00 -04:00
2008-10-08 14:22:53 -04:00
HELP: real-user-id
2008-11-05 05:27:12 -05:00
{ $values { "id" integer } }
2008-10-08 14:05:00 -04:00
{ $description "The real user id of the current user." } ;
2008-10-08 14:22:53 -04:00
HELP: set-effective-user
2008-11-05 05:27:12 -05:00
{ $values { "string/id" "a string or a user id" } }
2009-01-07 15:53:43 -05:00
{ $description "Sets the current effective user given a user-name or a user id." } ;
2008-10-08 14:05:00 -04:00
2008-10-08 14:22:53 -04:00
HELP: set-real-user
2008-11-05 05:27:12 -05:00
{ $values { "string/id" "a string or a user id" } }
2009-01-07 15:53:43 -05:00
{ $description "Sets the current real user given a user-name or a user id." } ;
2008-10-08 14:05:00 -04:00
HELP: user-passwd
{ $values
{ "obj" object }
2009-01-04 12:44:49 -05:00
{ "passwd/f" "passwd or f" } }
2009-01-07 15:53:43 -05:00
{ $description "Returns the passwd tuple given a user-name string or user id." } ;
2008-10-08 14:05:00 -04:00
2009-01-07 15:53:43 -05:00
HELP: user-name
2008-10-08 14:05:00 -04:00
{ $values
{ "id" integer }
{ "string" string } }
2009-01-07 15:53:43 -05:00
{ $description "Returns the user-name associated with the user id." } ;
2008-10-08 14:05:00 -04:00
2008-10-08 14:22:53 -04:00
HELP: user-id
2008-10-08 14:05:00 -04:00
{ $values
{ "string" string }
{ "id" integer } }
2009-01-07 15:53:43 -05:00
{ $description "Returns the user id associated with the user-name." } ;
2008-10-08 14:05:00 -04:00
2008-10-08 14:22:53 -04:00
HELP: with-effective-user
2008-10-08 14:05:00 -04:00
{ $values
{ "string/id" "a string or a uid" } { "quot" quotation } }
2009-01-07 15:53:43 -05:00
{ $description "Sets the effective user-name and calls the quotation. Restores the current user-name on success or on error after the call." } ;
2008-10-08 14:05:00 -04:00
2008-11-11 14:05:04 -05:00
HELP: with-user-cache
2008-10-08 14:05:00 -04:00
{ $values
{ "quot" quotation } }
2008-11-11 14:05:04 -05:00
{ $description "Iterates over the password file using library calls and creates a cache in the " { $link user-cache } " symbol. The cache is a hashtable indexed by user id. When looking up many users, this approach is much faster than calling system calls." } ;
2008-10-08 14:05:00 -04:00
2008-10-08 14:22:53 -04:00
HELP: with-real-user
2008-10-08 14:05:00 -04:00
{ $values
{ "string/id" "a string or a uid" } { "quot" quotation } }
2009-01-07 15:53:43 -05:00
{ $description "Sets the real user-name and calls the quotation. Restores the current user-name on success or on error after the call." } ;
2008-10-08 14:05:00 -04:00
{
2009-01-07 15:53:43 -05:00
real-user-name real-user-id set-real-user
effective-user-name effective-user-id
2008-10-08 14:22:53 -04:00
set-effective-user
2008-10-08 14:05:00 -04:00
} related-words
2008-11-05 05:27:12 -05:00
ARTICLE: "unix.users" "Unix users"
2008-10-08 14:05:00 -04:00
"The " { $vocab-link "unix.users" } " vocabulary contains words that return information about Unix users."
2008-11-05 05:27:12 -05:00
$nl
2008-10-08 14:05:00 -04:00
"Listing all users:"
{ $subsection all-users }
"Real user:"
2009-01-07 15:53:43 -05:00
{ $subsection real-user-name }
2008-10-08 14:22:53 -04:00
{ $subsection real-user-id }
{ $subsection set-real-user }
2008-10-08 14:05:00 -04:00
"Effective user:"
2009-01-07 15:53:43 -05:00
{ $subsection effective-user-name }
2008-10-08 14:22:53 -04:00
{ $subsection effective-user-id }
{ $subsection set-effective-user }
2008-10-08 14:05:00 -04:00
"Combinators to change users:"
2008-10-08 14:22:53 -04:00
{ $subsection with-real-user }
{ $subsection with-effective-user } ;
2008-10-08 14:05:00 -04:00
ABOUT: "unix.users"