#include "includes.h"
#include "libcli/security/privileges.h"
+#include "libcli/security/privileges_private.h"
#include "librpc/gen_ndr/security.h"
/* The use of strcasecmp here is safe, all the comparison strings are ASCII */
#undef strcasecmp
-#define NUM_SHORT_LIST_PRIVS 8
+#define NUM_SHORT_LIST_PRIVS 9
static const struct {
enum sec_privilege luid;
{SEC_PRIV_PRINT_OPERATOR, SEC_PRIV_PRINT_OPERATOR_BIT, "SePrintOperatorPrivilege", "Manage printers"},
{SEC_PRIV_ADD_USERS, SEC_PRIV_ADD_USERS_BIT, "SeAddUsersPrivilege", "Add users and groups to the domain"},
{SEC_PRIV_DISK_OPERATOR, SEC_PRIV_DISK_OPERATOR_BIT, "SeDiskOperatorPrivilege", "Manage disk shares"},
+ {SEC_PRIV_SECURITY, SEC_PRIV_SECURITY_BIT, "SeSecurityPrivilege", "System security"},
- /* The list from here on was not displayed in the code from
- * source3/ with the comment that usrmgr will display these
- * next 2 twice if you include them. The source4/ code has
- * always included them, but they do not appear in Windows
- * 2008 R2.
- Finally, the parameter 'short_list' determines if the short
- or full list (including many other privileges) is used */
-
- {SEC_PRIV_SECURITY,
- SEC_PRIV_SECURITY_BIT,
- "SeSecurityPrivilege",
- "System security"},
+ /* The list from here on is not displayed in the code from
+ * source3, and is after index NUM_SHORT_LIST_PRIVS for that
+ * reason */
{SEC_PRIV_SYSTEMTIME,
SEC_PRIV_SYSTEMTIME_BIT,
SEC_PRIV_ENABLE_DELEGATION_BIT,
"SeEnableDelegationPrivilege",
"Enable Delegation"},
+};
- {SEC_PRIV_INTERACTIVE_LOGON,
- SEC_PRIV_INTERACTIVE_LOGON_BIT,
+/* These are rights, not privileges, and should not be confused. The
+ * names are very similar, and they are quite similar in behaviour,
+ * but they are not to be enumerated as a system-wide list or have an
+ * LUID value */
+static const struct {
+ uint32_t right_mask;
+ const char *name;
+ const char *description;
+} rights[] = {
+ {LSA_POLICY_MODE_INTERACTIVE,
"SeInteractiveLogonRight",
"Interactive logon"},
- {SEC_PRIV_NETWORK_LOGON,
- SEC_PRIV_NETWORK_LOGON_BIT,
+ {LSA_POLICY_MODE_NETWORK,
"SeNetworkLogonRight",
"Network logon"},
- {SEC_PRIV_REMOTE_INTERACTIVE_LOGON,
- SEC_PRIV_REMOTE_INTERACTIVE_LOGON_BIT,
+ {LSA_POLICY_MODE_REMOTE_INTERACTIVE,
"SeRemoteInteractiveLogonRight",
"Remote Interactive logon"}
};
/*
return a privilege mask given a privilege id
*/
-static uint64_t sec_privilege_mask(enum sec_privilege privilege)
+uint64_t sec_privilege_mask(enum sec_privilege privilege)
{
int i;
for (i=0;i<ARRAY_SIZE(privs);i++) {
put all valid privileges into a mask
****************************************************************************/
-bool se_priv_put_all_privileges(uint64_t *privilege_mask)
+void se_priv_put_all_privileges(uint64_t *privilege_mask)
{
int i;
- uint32_t num_privs = ARRAY_SIZE(privs);
*privilege_mask = 0;
- for ( i=0; i<num_privs; i++ ) {
+ for ( i=0; i<ARRAY_SIZE(privs); i++ ) {
*privilege_mask |= privs[i].privilege_mask;
}
- return true;
}
/*********************************************************************
bool se_priv_from_name( const char *name, uint64_t *privilege_mask )
{
int i;
- uint32_t num_privs = ARRAY_SIZE(privs);
- for ( i=0; i<num_privs; i++ ) {
+ for ( i=0; i<ARRAY_SIZE(privs); i++ ) {
if ( strequal( privs[i].name, name ) ) {
*privilege_mask = privs[i].privilege_mask;
return true;
{
int i;
- uint32_t num_privs = ARRAY_SIZE(privs);
-
if (!name) {
return NULL;
}
- for ( i=0; i<num_privs; i++ ) {
+ for ( i=0; i<ARRAY_SIZE(privs); i++ ) {
if ( strequal( privs[i].name, name ) ) {
return privs[i].description;
}
bool se_priv_to_privilege_set( PRIVILEGE_SET *set, uint64_t privilege_mask )
{
int i;
- uint32_t num_privs = ARRAY_SIZE(privs);
struct lsa_LUIDAttribute luid;
luid.attribute = 0;
luid.luid.high = 0;
- for ( i=0; i<num_privs; i++ ) {
+ for ( i=0; i<ARRAY_SIZE(privs); i++ ) {
if ((privilege_mask & privs[i].privilege_mask) == 0)
continue;
bool privilege_set_to_se_priv( uint64_t *privilege_mask, struct lsa_PrivilegeSet *privset )
{
- int i;
+ uint32_t i;
ZERO_STRUCTP( privilege_mask );
const char *sec_privilege_display_name(enum sec_privilege privilege, uint16_t *language)
{
int i;
- if (privilege < 1 || privilege > 64) {
- return NULL;
- }
for (i=0;i<ARRAY_SIZE(privs);i++) {
if (privs[i].luid == privilege) {
return privs[i].description;
}
/*
- map a privilege name to a privilege id. Return -1 if not found
+ map a privilege name to a privilege id. Return SEC_PRIV_INVALID if not found
*/
enum sec_privilege sec_privilege_id(const char *name)
{
return SEC_PRIV_INVALID;
}
+/*
+ map a 'right' name to it's bitmap value. Return 0 if not found
+*/
+uint32_t sec_right_bit(const char *name)
+{
+ int i;
+ for (i=0;i<ARRAY_SIZE(rights);i++) {
+ if (strcasecmp(rights[i].name, name) == 0) {
+ return rights[i].right_mask;
+ }
+ }
+ return 0;
+}
+
/*
assist in walking the table of privileges - return the LUID (low 32 bits) by index
*/
if (idx >= 0 && idx<ARRAY_SIZE(privs)) {
return privs[idx].luid;
}
- return -1;
+ return SEC_PRIV_INVALID;
}
/*
{
uint64_t mask;
+ if (!token) {
+ return false;
+ }
+
mask = sec_privilege_mask(privilege);
if (mask == 0) {
return false;
return false;
}
+bool security_token_system_privilege(const struct security_token *token)
+{
+ if (token == NULL) {
+ return false;
+ }
+
+ if (token->privilege_mask == (uint64_t)~0) {
+ return true;
+ }
+
+ return false;
+}
+
/*
set a bit in the privilege mask
*/
token->privilege_mask |= sec_privilege_mask(privilege);
}
-void security_token_debug_privileges(int dbg_lev, const struct security_token *token)
+/*
+ set a bit in the rights mask
+*/
+void security_token_set_right_bit(struct security_token *token, uint32_t right_bit)
+{
+ token->rights_mask |= right_bit;
+}
+
+void security_token_debug_privileges(int dbg_class, int dbg_lev, const struct security_token *token)
{
- DEBUGADD(dbg_lev, (" Privileges (0x%16llX):\n",
- (unsigned long long) token->privilege_mask));
+ DEBUGADDC(dbg_class, dbg_lev, (" Privileges (0x%16llX):\n",
+ (unsigned long long) token->privilege_mask));
if (token->privilege_mask) {
int idx = 0;
int i = 0;
for (idx = 0; idx<ARRAY_SIZE(privs); idx++) {
if (token->privilege_mask & privs[idx].privilege_mask) {
- DEBUGADD(dbg_lev, (" Privilege[%3lu]: %s\n", (unsigned long)i++,
- privs[idx].name));
+ DEBUGADDC(dbg_class, dbg_lev,
+ (" Privilege[%3lu]: %s\n", (unsigned long)i++,
+ privs[idx].name));
+ }
+ }
+ }
+ DEBUGADDC(dbg_class, dbg_lev, (" Rights (0x%16lX):\n",
+ (unsigned long) token->rights_mask));
+
+ if (token->rights_mask) {
+ int idx = 0;
+ int i = 0;
+ for (idx = 0; idx<ARRAY_SIZE(rights); idx++) {
+ if (token->rights_mask & rights[idx].right_mask) {
+ DEBUGADDC(dbg_class, dbg_lev,
+ (" Right[%3lu]: %s\n", (unsigned long)i++,
+ rights[idx].name));
}
}
}