Allow with-*-group/user to be a no-op if first parameter is f
							parent
							
								
									27af7ffe50
								
							
						
					
					
						commit
						82f38ce9a1
					
				| 
						 | 
					@ -65,8 +65,8 @@ HELP: user-groups
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HELP: with-effective-group
 | 
					HELP: with-effective-group
 | 
				
			||||||
{ $values
 | 
					{ $values
 | 
				
			||||||
     { "string/id" "a string or a group id" } { "quot" quotation } }
 | 
					     { "string/id/f" "a string, a group id, or f" } { "quot" quotation } }
 | 
				
			||||||
{ $description "Sets the effective group name and calls the quotation. Restors the effective group name on success or on error after the call." } ;
 | 
					{ $description "Sets the effective group name and calls the quotation. Restors the effective group name on success or on error after the call. If the first parameter is " { $link f } ", the quotation is called as the current user." } ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HELP: with-group-cache
 | 
					HELP: with-group-cache
 | 
				
			||||||
{ $values
 | 
					{ $values
 | 
				
			||||||
| 
						 | 
					@ -75,8 +75,8 @@ HELP: with-group-cache
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HELP: with-real-group
 | 
					HELP: with-real-group
 | 
				
			||||||
{ $values
 | 
					{ $values
 | 
				
			||||||
     { "string/id" "a string or a group id" } { "quot" quotation } }
 | 
					     { "string/id/f" "a string or a group id" } { "quot" quotation } }
 | 
				
			||||||
{ $description "Sets the real group name and calls the quotation. Restores the current group name on success or on error after the call." } ;
 | 
					{ $description "Sets the real group name and calls the quotation. Restores the current group name on success or on error after the call. If the first parameter is " { $link f } ", the quotation is called as the current user." } ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ARTICLE: "unix.groups" "Unix groups"
 | 
					ARTICLE: "unix.groups" "Unix groups"
 | 
				
			||||||
"The " { $vocab-link "unix.groups" } " vocabulary contains words that return information about Unix groups."
 | 
					"The " { $vocab-link "unix.groups" } " vocabulary contains words that return information about Unix groups."
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,3 +28,6 @@ IN: unix.groups.tests
 | 
				
			||||||
[ f ]
 | 
					[ f ]
 | 
				
			||||||
[ "please-oh-please-don't-have-a-group-named-this123lalala" group-struct ] unit-test
 | 
					[ "please-oh-please-don't-have-a-group-named-this123lalala" group-struct ] unit-test
 | 
				
			||||||
[ "please-oh-please-don't-have-a-group-named-this123lalala" ?group-id ] must-fail
 | 
					[ "please-oh-please-don't-have-a-group-named-this123lalala" ?group-id ] must-fail
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ 3 ] [ f [ 3 ] with-effective-group ] unit-test
 | 
				
			||||||
 | 
					[ 3 ] [ f [ 3 ] with-real-group ] unit-test
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -109,14 +109,20 @@ GENERIC: set-real-group ( obj -- )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GENERIC: set-effective-group ( obj -- )
 | 
					GENERIC: set-effective-group ( obj -- )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: with-real-group ( string/id quot -- )
 | 
					: (with-real-group) ( string/id quot -- )
 | 
				
			||||||
    '[ _ set-real-group @ ]
 | 
					    '[ _ set-real-group @ ]
 | 
				
			||||||
    real-group-id '[ _ set-real-group ] [ ] cleanup ; inline
 | 
					    real-group-id '[ _ set-real-group ] [ ] cleanup ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: with-effective-group ( string/id quot -- )
 | 
					: with-real-group ( string/id/f quot -- )
 | 
				
			||||||
 | 
					    over [ (with-real-group) ] [ nip call ] if ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					: (with-effective-group) ( string/id quot -- )
 | 
				
			||||||
    '[ _ set-effective-group @ ]
 | 
					    '[ _ set-effective-group @ ]
 | 
				
			||||||
    effective-group-id '[ _ set-effective-group ] [ ] cleanup ; inline
 | 
					    effective-group-id '[ _ set-effective-group ] [ ] cleanup ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					: with-effective-group ( string/id/f quot -- )
 | 
				
			||||||
 | 
					    over [ (with-effective-group) ] [ nip call ] if ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<PRIVATE
 | 
					<PRIVATE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: (set-real-group) ( id -- )
 | 
					: (set-real-group) ( id -- )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,8 +67,8 @@ HELP: user-id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HELP: with-effective-user
 | 
					HELP: with-effective-user
 | 
				
			||||||
{ $values
 | 
					{ $values
 | 
				
			||||||
     { "string/id" "a string or a uid" } { "quot" quotation } }
 | 
					     { "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." } ;
 | 
					{ $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." } ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HELP: with-user-cache
 | 
					HELP: with-user-cache
 | 
				
			||||||
{ $values
 | 
					{ $values
 | 
				
			||||||
| 
						 | 
					@ -77,8 +77,8 @@ HELP: with-user-cache
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HELP: with-real-user
 | 
					HELP: with-real-user
 | 
				
			||||||
{ $values
 | 
					{ $values
 | 
				
			||||||
     { "string/id" "a string or a uid" } { "quot" quotation } }
 | 
					     { "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." } ;
 | 
					{ $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." } ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    real-user-name real-user-id set-real-user
 | 
					    real-user-name real-user-id set-real-user
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,3 +28,6 @@ IN: unix.users.tests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[ f ] [ "thisusershouldnotexistabcdefg12345asdfasdfasdfasdfasdfasdfasdf" user-id ] unit-test
 | 
					[ f ] [ "thisusershouldnotexistabcdefg12345asdfasdfasdfasdfasdfasdfasdf" user-id ] unit-test
 | 
				
			||||||
[ "thisusershouldnotexistabcdefg12345asdfasdfasdfasdfasdfasdfasdf" ?user-id ] must-fail
 | 
					[ "thisusershouldnotexistabcdefg12345asdfasdfasdfasdfasdfasdfasdf" ?user-id ] must-fail
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[ 3 ] [ f [ 3 ] with-effective-user ] unit-test
 | 
				
			||||||
 | 
					[ 3 ] [ f [ 3 ] with-real-user ] unit-test
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -85,16 +85,22 @@ GENERIC: set-real-user ( string/id -- )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GENERIC: set-effective-user ( string/id -- )
 | 
					GENERIC: set-effective-user ( string/id -- )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: with-real-user ( string/id quot -- )
 | 
					: (with-real-user) ( string/id quot -- )
 | 
				
			||||||
    '[ _ set-real-user @ ]
 | 
					    '[ _ set-real-user @ ]
 | 
				
			||||||
    real-user-id '[ _ set-real-user ]
 | 
					    real-user-id '[ _ set-real-user ]
 | 
				
			||||||
    [ ] cleanup ; inline
 | 
					    [ ] cleanup ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: with-effective-user ( string/id quot -- )
 | 
					: with-real-user ( string/id/f quot -- )
 | 
				
			||||||
 | 
					    over [ (with-real-user) ] [ nip call ] if ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					: (with-effective-user) ( string/id quot -- )
 | 
				
			||||||
    '[ _ set-effective-user @ ]
 | 
					    '[ _ set-effective-user @ ]
 | 
				
			||||||
    effective-user-id '[ _ set-effective-user ]
 | 
					    effective-user-id '[ _ set-effective-user ]
 | 
				
			||||||
    [ ] cleanup ; inline
 | 
					    [ ] cleanup ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					: with-effective-user ( string/id/f quot -- )
 | 
				
			||||||
 | 
					    over [ (with-effective-user) ] [ nip call ] if ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<PRIVATE
 | 
					<PRIVATE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
: (set-real-user) ( id -- )
 | 
					: (set-real-user) ( id -- )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue