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  
						 
					
						
							
								
									
										
										
										
											2011-01-04 07:51:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "A platform-specific tuple corresponding to every field from the Unix passwd struct. BSD passwd structures have four extra slots: "  { $slot "change"  } ", "  { $slot "class"  } ", "  { $slot "expire"  } ", "  { $slot "fields"  } "."  } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-08 14:05:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											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  }
							 
						 
					
						
							
								
									
										
										
										
											2010-02-05 02:20:40 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "id/f"  "an integer or f"  } }
							 
						 
					
						
							
								
									
										
										
										
											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
							 
						 
					
						
							
								
									
										
										
										
											2010-06-17 14:20:51 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "string/id/f"  "a string, a uid, or f"  } { "quot"  quotation } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Sets the effective user-name and calls the quotation. Restores the current user-name on success or on error after the call. If the first parameter is "  { $link f  } ", the quotation is called as the current user."  } ;
 
							 
						 
					
						
							
								
									
										
										
										
											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
							 
						 
					
						
							
								
									
										
										
										
											2010-06-17 14:20:51 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     { "string/id/f"  "a string, a uid, or f"  } { "quot"  quotation } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Sets the real user-name and calls the quotation. Restores the current user-name on success or on error after the call. If the first parameter is "  { $link f  } ", the quotation is called as the current user."  } ;
 
							 
						 
					
						
							
								
									
										
										
										
											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
							 
						 
					
						
							
								
									
										
										
										
											2011-01-04 07:51:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    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
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-06-21 13:07:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  ?user-id  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "string"  string  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "id/f"  "an integer or "  { $link f  } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Returns a group id or throws an exception."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  all-user-names  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2011-01-04 07:51:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-06-21 13:07:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    { "seq"  sequence  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Returns a sequence of group names as strings."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  user-exists?  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "name/id"  "a string or an integer"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "?"  boolean  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Returns a boolean representing the user's existence."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											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:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections all-users }
							 
						 
					
						
							
								
									
										
										
										
											2010-06-21 13:07:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Listing all user names:"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsections all-user-names }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"Checking if a user exists:"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsections user-exists? }
							 
						 
					
						
							
								
									
										
										
										
											2010-06-21 13:10:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Querying/setting the current real user:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    real-user-name
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    real-user-id
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    set-real-user
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2010-06-21 13:10:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Querying/setting the current effective user:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    effective-user-name
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    effective-user-id
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    set-effective-user
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2008-10-08 14:05:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								"Combinators to change users:"  
						 
					
						
							
								
									
										
										
										
											2009-10-01 15:56:36 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsections
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with-real-user
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with-effective-user
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-08 14:05:00 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ABOUT: "unix.users"