#include "includes.h"
+#include "dbwrap.h"
#define PRIVPREFIX "PRIV_"
typedef struct {
- size_t count;
+ uint32_t count;
struct dom_sid *list;
} SID_LIST;
typedef struct {
TALLOC_CTX *mem_ctx;
- SE_PRIV privilege;
+ uint64_t privilege;
SID_LIST sids;
} PRIV_SID_LIST;
-static bool get_privileges( const struct dom_sid *sid, SE_PRIV *mask )
+static bool get_privileges( const struct dom_sid *sid, uint64_t *mask )
{
struct db_context *db = get_account_pol_db();
fstring tmp, keystr;
return False;
}
- SMB_ASSERT( data.dsize == sizeof( SE_PRIV ) );
+ if (data.dsize == 4*4) {
+ DEBUG(3, ("get_privileges: Should not have obtained old-style privileges record for SID "
+ "[%s]\n", sid_string_dbg(sid)));
+ return False;
+ }
+
+ if (data.dsize != sizeof( uint64_t ) ) {
+ DEBUG(3, ("get_privileges: Invalid privileges record assigned to SID "
+ "[%s]\n", sid_string_dbg(sid)));
+ return False;
+ }
+
+ *mask = BVAL(data.dptr, 0);
- se_priv_copy( mask, (SE_PRIV*)data.dptr );
TALLOC_FREE(data.dptr);
return True;
Store the privilege mask (set) for a given SID
****************************************************************************/
-static bool set_privileges( const struct dom_sid *sid, SE_PRIV *mask )
+static bool set_privileges( const struct dom_sid *sid, uint64_t *mask )
{
struct db_context *db = get_account_pol_db();
+ uint8_t privbuf[8];
fstring tmp, keystr;
TDB_DATA data;
fstr_sprintf(keystr, "%s%s", PRIVPREFIX, sid_to_fstring(tmp, sid));
- /* no packing. static size structure, just write it out */
+ /* This writes the 64 bit bitmask out in little endian format */
+ SBVAL(privbuf,0,*mask);
data.dptr = (uint8 *)mask;
- data.dsize = sizeof(SE_PRIV);
+ data.dsize = sizeof(uint64_t);
return NT_STATUS_IS_OK(dbwrap_store_bystring(db, keystr, data,
TDB_REPLACE));
get a list of all privileges for all sids in the list
*********************************************************************/
-bool get_privileges_for_sids(SE_PRIV *privileges, struct dom_sid *slist, int scount)
+bool get_privileges_for_sids(uint64_t *privileges, struct dom_sid *slist, int scount)
{
- SE_PRIV mask;
+ uint64_t mask;
int i;
bool found = False;
continue;
DEBUG(5,("get_privileges_for_sids: sid = %s\nPrivilege "
- "set:\n", sid_string_dbg(&slist[i])));
- dump_se_priv( DBGC_ALL, 5, &mask );
+ "set: 0x%llx\n", sid_string_dbg(&slist[i]),
+ (unsigned long long)mask));
se_priv_add( privileges, &mask );
found = True;
/* easy check first */
- if (rec->value.dsize != sizeof(SE_PRIV) )
+ if (rec->value.dsize != sizeof(uint64_t) )
return 0;
/* check we have a PRIV_+SID entry */
/* check to see if we are looking for a particular privilege */
if ( !se_priv_equal(&priv->privilege, &se_priv_none) ) {
- SE_PRIV mask;
+ uint64_t mask;
- se_priv_copy( &mask, (SE_PRIV*)rec->value.dptr );
+ se_priv_copy( &mask, (uint64_t*)rec->value.dptr );
/* if the SID does not have the specified privilege
then just return */
Retrieve list of SIDs granted a particular privilege
*********************************************************************/
-NTSTATUS privilege_enum_sids(const SE_PRIV *mask, TALLOC_CTX *mem_ctx,
+NTSTATUS privilege_enum_sids(const uint64_t *mask, TALLOC_CTX *mem_ctx,
struct dom_sid **sids, int *num_sids)
{
struct db_context *db = get_account_pol_db();
Add privilege to sid
****************************************************************************/
-bool grant_privilege(const struct dom_sid *sid, const SE_PRIV *priv_mask)
+bool grant_privilege(const struct dom_sid *sid, const uint64_t priv_mask)
{
- SE_PRIV old_mask, new_mask;
+ uint64_t old_mask, new_mask;
ZERO_STRUCT( old_mask );
ZERO_STRUCT( new_mask );
if ( get_privileges( sid, &old_mask ) )
- se_priv_copy( &new_mask, &old_mask );
+ new_mask = old_mask;
else
- se_priv_copy( &new_mask, &se_priv_none );
+ new_mask = 0;
- se_priv_add( &new_mask, priv_mask );
+ new_mask |= priv_mask;
DEBUG(10,("grant_privilege: %s\n", sid_string_dbg(sid)));
- DEBUGADD( 10, ("original privilege mask:\n"));
- dump_se_priv( DBGC_ALL, 10, &old_mask );
+ DEBUGADD( 10, ("original privilege mask: 0x%llx\n", (unsigned long long)new_mask));
- DEBUGADD( 10, ("new privilege mask:\n"));
- dump_se_priv( DBGC_ALL, 10, &new_mask );
+ DEBUGADD( 10, ("new privilege mask: 0x%llx\n", (unsigned long long)new_mask));
return set_privileges( sid, &new_mask );
}
bool grant_privilege_by_name(struct dom_sid *sid, const char *name)
{
- SE_PRIV mask;
+ uint64_t mask;
if (! se_priv_from_name(name, &mask)) {
DEBUG(3, ("grant_privilege_by_name: "
return False;
}
- return grant_privilege( sid, &mask );
+ return grant_privilege( sid, mask );
}
/***************************************************************************
Remove privilege from sid
****************************************************************************/
-bool revoke_privilege(const struct dom_sid *sid, const SE_PRIV *priv_mask)
+bool revoke_privilege(const struct dom_sid *sid, const uint64_t priv_mask)
{
- SE_PRIV mask;
+ uint64_t mask;
/* if the user has no privileges, then we can't revoke any */
DEBUG(10,("revoke_privilege: %s\n", sid_string_dbg(sid)));
- DEBUGADD( 10, ("original privilege mask:\n"));
- dump_se_priv( DBGC_ALL, 10, &mask );
+ DEBUGADD( 10, ("original privilege mask: 0x%llx\n", (unsigned long long)mask));
- se_priv_remove( &mask, priv_mask );
+ mask &= ~priv_mask;
- DEBUGADD( 10, ("new privilege mask:\n"));
- dump_se_priv( DBGC_ALL, 10, &mask );
+ DEBUGADD( 10, ("new privilege mask: 0x%llx\n", (unsigned long long)mask));
return set_privileges( sid, &mask );
}
bool revoke_all_privileges( struct dom_sid *sid )
{
- return revoke_privilege( sid, &se_priv_all );
+ return revoke_privilege( sid, SE_ALL_PRIVS);
}
/*********************************************************************
bool revoke_privilege_by_name(struct dom_sid *sid, const char *name)
{
- SE_PRIV mask;
+ uint64_t mask;
if (! se_priv_from_name(name, &mask)) {
DEBUG(3, ("revoke_privilege_by_name: "
return False;
}
- return revoke_privilege(sid, &mask);
+ return revoke_privilege(sid, mask);
}
NTSTATUS privilege_create_account(const struct dom_sid *sid )
{
- return ( grant_privilege(sid, &se_priv_none) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL);
+ return ( grant_privilege(sid, 0) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL);
}
/***************************************************************************
duplicate alloc luid_attr
****************************************************************************/
-NTSTATUS dup_luid_attr(TALLOC_CTX *mem_ctx, LUID_ATTR **new_la, LUID_ATTR *old_la, int count)
+NTSTATUS dup_luid_attr(TALLOC_CTX *mem_ctx, struct lsa_LUIDAttribute **new_la, struct lsa_LUIDAttribute *old_la, int count)
{
int i;
return NT_STATUS_OK;
if (count) {
- *new_la = TALLOC_ARRAY(mem_ctx, LUID_ATTR, count);
+ *new_la = TALLOC_ARRAY(mem_ctx, struct lsa_LUIDAttribute, count);
if ( !*new_la ) {
- DEBUG(0,("dup_luid_attr: failed to alloc new LUID_ATTR array [%d]\n", count));
+ DEBUG(0,("dup_luid_attr: failed to alloc new struct lsa_LUIDAttribute array [%d]\n", count));
return NT_STATUS_NO_MEMORY;
}
} else {
for (i=0; i<count; i++) {
(*new_la)[i].luid.high = old_la[i].luid.high;
(*new_la)[i].luid.low = old_la[i].luid.low;
- (*new_la)[i].attr = old_la[i].attr;
+ (*new_la)[i].attribute = old_la[i].attribute;
}
return NT_STATUS_OK;
bool is_privileged_sid( const struct dom_sid *sid )
{
- SE_PRIV mask;
+ uint64_t mask;
return get_privileges( sid, &mask );
}
bool grant_all_privileges( const struct dom_sid *sid )
{
- SE_PRIV mask;
+ uint64_t mask;
if (!se_priv_put_all_privileges(&mask)) {
return False;
}
- return grant_privilege( sid, &mask );
+ return grant_privilege( sid, mask );
}