From 3c9e31d0f6955d05cc23d2422349bedf5bba9dba Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 23 Sep 2005 15:26:54 +0000 Subject: [PATCH] r10455: merging privilege fix from SAMBA_3_0 --- source/lib/privileges.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/source/lib/privileges.c b/source/lib/privileges.c index 8bb6108448b..760a33670a7 100644 --- a/source/lib/privileges.c +++ b/source/lib/privileges.c @@ -285,6 +285,11 @@ static BOOL set_privileges( const DOM_SID *sid, SE_PRIV *mask ) if ( !tdb ) return False; + if ( !sid || (sid->num_auths == 0) ) { + DEBUG(0,("set_privileges: Refusing to store empty SID!\n")); + return False; + } + /* PRIV_ (NULL terminated) as the key */ fstr_sprintf( keystr, "%s%s", PRIVPREFIX, sid_string_static(sid) ); @@ -497,6 +502,12 @@ static int priv_traverse_fn(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void *s fstrcpy( sid_string, &key.dptr[strlen(PRIVPREFIX)] ); + /* this is a last ditch safety check to preventing returning + and invalid SID (i've somehow run into this on development branches) */ + + if ( strcmp( "S-0-0", sid_string ) == 0 ) + return 0; + if ( !string_to_sid(&sid, sid_string) ) { DEBUG(0,("travsersal_fn_enum__acct: Could not convert SID [%s]\n", sid_string)); @@ -811,11 +822,28 @@ BOOL se_priv_to_privilege_set( PRIVILEGE_SET *set, SE_PRIV *mask ) /******************************************************************* *******************************************************************/ -BOOL privilege_set_to_se_priv( SE_PRIV *mask, PRIVILEGE_SET *privset ) +static BOOL luid_to_se_priv( LUID *luid, SE_PRIV *mask ) { int i; uint32 num_privs = count_all_privileges(); + for ( i=0; ilow == privs[i].luid.low ) { + se_priv_copy( mask, &privs[i].se_priv ); + return True; + } + } + + return False; +} + +/******************************************************************* +*******************************************************************/ + +BOOL privilege_set_to_se_priv( SE_PRIV *mask, PRIVILEGE_SET *privset ) +{ + int i; + ZERO_STRUCTP( mask ); for ( i=0; icount; i++ ) { @@ -827,12 +855,8 @@ BOOL privilege_set_to_se_priv( SE_PRIV *mask, PRIVILEGE_SET *privset ) if ( privset->set[i].luid.high != 0 ) return False; - /* make sure :LUID.low is in range */ - if ( privset->set[i].luid.low == 0 || privset->set[i].luid.low > num_privs ) - return False; - - r = privs[privset->set[i].luid.low - 1].se_priv; - se_priv_add( mask, &r ); + if ( luid_to_se_priv( &privset->set[i].luid, &r ) ) + se_priv_add( mask, &r ); } return True; -- 2.11.4.GIT