idx
int64 | func_before
string | Vulnerability Classification
string | vul
int64 | func_after
string | patch
string | CWE ID
string | lines_before
string | lines_after
string |
---|---|---|---|---|---|---|---|---|
0 | static bool check_rodc_critical_attribute(struct ldb_message *msg)
{
uint32_t schemaFlagsEx, searchFlags, rodc_filtered_flags;
schemaFlagsEx = ldb_msg_find_attr_as_uint(msg, "schemaFlagsEx", 0);
searchFlags = ldb_msg_find_attr_as_uint(msg, "searchFlags", 0);
rodc_filtered_flags = (SEARCH_FLAG_RODC_ATTRIBUTE
| SEARCH_FLAG_CONFIDENTIAL);
if ((schemaFlagsEx & SCHEMA_FLAG_ATTR_IS_CRITICAL) &&
((searchFlags & rodc_filtered_flags) == rodc_filtered_flags)) {
return true;
} else {
return false;
}
}
| Bypass | 0 | static bool check_rodc_critical_attribute(struct ldb_message *msg)
{
uint32_t schemaFlagsEx, searchFlags, rodc_filtered_flags;
schemaFlagsEx = ldb_msg_find_attr_as_uint(msg, "schemaFlagsEx", 0);
searchFlags = ldb_msg_find_attr_as_uint(msg, "searchFlags", 0);
rodc_filtered_flags = (SEARCH_FLAG_RODC_ATTRIBUTE
| SEARCH_FLAG_CONFIDENTIAL);
if ((schemaFlagsEx & SCHEMA_FLAG_ATTR_IS_CRITICAL) &&
((searchFlags & rodc_filtered_flags) == rodc_filtered_flags)) {
return true;
} else {
return false;
}
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
1 | static int samldb_add_entry(struct samldb_ctx *ac)
{
struct ldb_context *ldb;
struct ldb_request *req;
int ret;
ldb = ldb_module_get_ctx(ac->module);
ret = ldb_build_add_req(&req, ldb, ac,
ac->msg,
ac->req->controls,
ac, samldb_add_entry_callback,
ac->req);
LDB_REQ_SET_LOCATION(req);
if (ret != LDB_SUCCESS) {
return ret;
}
return ldb_next_request(ac->module, req);
}
| Bypass | 0 | static int samldb_add_entry(struct samldb_ctx *ac)
{
struct ldb_context *ldb;
struct ldb_request *req;
int ret;
ldb = ldb_module_get_ctx(ac->module);
ret = ldb_build_add_req(&req, ldb, ac,
ac->msg,
ac->req->controls,
ac, samldb_add_entry_callback,
ac->req);
LDB_REQ_SET_LOCATION(req);
if (ret != LDB_SUCCESS) {
return ret;
}
return ldb_next_request(ac->module, req);
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
2 | static int samldb_add_entry_callback(struct ldb_request *req,
struct ldb_reply *ares)
{
struct ldb_context *ldb;
struct samldb_ctx *ac;
int ret;
ac = talloc_get_type(req->context, struct samldb_ctx);
ldb = ldb_module_get_ctx(ac->module);
if (!ares) {
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR);
}
if (ares->type == LDB_REPLY_REFERRAL) {
return ldb_module_send_referral(ac->req, ares->referral);
}
if (ares->error != LDB_SUCCESS) {
return ldb_module_done(ac->req, ares->controls,
ares->response, ares->error);
}
if (ares->type != LDB_REPLY_DONE) {
ldb_asprintf_errstring(ldb, "Invalid LDB reply type %d", ares->type);
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR);
}
/* The caller may wish to get controls back from the add */
ac->ares = talloc_steal(ac, ares);
ret = samldb_next_step(ac);
if (ret != LDB_SUCCESS) {
return ldb_module_done(ac->req, NULL, NULL, ret);
}
return ret;
}
| Bypass | 0 | static int samldb_add_entry_callback(struct ldb_request *req,
struct ldb_reply *ares)
{
struct ldb_context *ldb;
struct samldb_ctx *ac;
int ret;
ac = talloc_get_type(req->context, struct samldb_ctx);
ldb = ldb_module_get_ctx(ac->module);
if (!ares) {
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR);
}
if (ares->type == LDB_REPLY_REFERRAL) {
return ldb_module_send_referral(ac->req, ares->referral);
}
if (ares->error != LDB_SUCCESS) {
return ldb_module_done(ac->req, ares->controls,
ares->response, ares->error);
}
if (ares->type != LDB_REPLY_DONE) {
ldb_asprintf_errstring(ldb, "Invalid LDB reply type %d", ares->type);
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR);
}
/* The caller may wish to get controls back from the add */
ac->ares = talloc_steal(ac, ares);
ret = samldb_next_step(ac);
if (ret != LDB_SUCCESS) {
return ldb_module_done(ac->req, NULL, NULL, ret);
}
return ret;
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
3 | static int samldb_add_handle_msDS_IntId(struct samldb_ctx *ac)
{
int ret;
bool id_exists;
uint32_t msds_intid;
int32_t system_flags;
struct ldb_context *ldb;
struct ldb_result *ldb_res;
struct ldb_dn *schema_dn;
struct samldb_msds_intid_persistant *msds_intid_struct;
struct dsdb_schema *schema;
ldb = ldb_module_get_ctx(ac->module);
schema_dn = ldb_get_schema_basedn(ldb);
/* replicated update should always go through */
if (ldb_request_get_control(ac->req,
DSDB_CONTROL_REPLICATED_UPDATE_OID)) {
return LDB_SUCCESS;
}
/* msDS-IntId is handled by system and should never be
* passed by clients */
if (ldb_msg_find_element(ac->msg, "msDS-IntId")) {
return LDB_ERR_UNWILLING_TO_PERFORM;
}
/* do not generate msDS-IntId if Relax control is passed */
if (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
return LDB_SUCCESS;
}
/* check Functional Level */
if (dsdb_functional_level(ldb) < DS_DOMAIN_FUNCTION_2003) {
return LDB_SUCCESS;
}
/* check systemFlags for SCHEMA_BASE_OBJECT flag */
system_flags = ldb_msg_find_attr_as_int(ac->msg, "systemFlags", 0);
if (system_flags & SYSTEM_FLAG_SCHEMA_BASE_OBJECT) {
return LDB_SUCCESS;
}
schema = dsdb_get_schema(ldb, NULL);
if (!schema) {
ldb_debug_set(ldb, LDB_DEBUG_FATAL,
"samldb_schema_info_update: no dsdb_schema loaded");
DEBUG(0,(__location__ ": %s\n", ldb_errstring(ldb)));
return ldb_operr(ldb);
}
msds_intid_struct = (struct samldb_msds_intid_persistant*) ldb_get_opaque(ldb, SAMLDB_MSDS_INTID_OPAQUE);
if (!msds_intid_struct) {
msds_intid_struct = talloc(ldb, struct samldb_msds_intid_persistant);
/* Generate new value for msDs-IntId
* Value should be in 0x80000000..0xBFFFFFFF range */
msds_intid = generate_random() % 0X3FFFFFFF;
msds_intid += 0x80000000;
msds_intid_struct->msds_intid = msds_intid;
msds_intid_struct->usn = schema->loaded_usn;
DEBUG(2, ("No samldb_msds_intid_persistant struct, allocating a new one\n"));
} else {
msds_intid = msds_intid_struct->msds_intid;
}
/* probe id values until unique one is found */
do {
uint64_t current_usn;
msds_intid++;
if (msds_intid > 0xBFFFFFFF) {
msds_intid = 0x80000001;
}
/*
* Alternative strategy to a costly (even indexed search) to the
* database.
* We search in the schema if we have already this intid (using dsdb_attribute_by_attributeID_id because
* in the range 0x80000000 0xBFFFFFFFF, attributeID is a DSDB_ATTID_TYPE_INTID).
* If so generate another random value.
* If not check if the highest USN in the database for the schema partition is the
* one that we know.
* If so it means that's only this ldb context that is touching the schema in the database.
* If not it means that's someone else has modified the database while we are doing our changes too
* (this case should be very bery rare) in order to be sure do the search in the database.
*/
if (dsdb_attribute_by_attributeID_id(schema, msds_intid)) {
msds_intid = generate_random() % 0X3FFFFFFF;
msds_intid += 0x80000000;
continue;
}
ret = dsdb_module_load_partition_usn(ac->module, schema_dn,
¤t_usn, NULL, NULL);
if (ret != LDB_SUCCESS) {
ldb_debug_set(ldb, LDB_DEBUG_ERROR,
__location__": Searching for schema USN failed: %s\n",
ldb_errstring(ldb));
return ldb_operr(ldb);
}
/* current_usn can be lesser than msds_intid_struct-> if there is
* uncommited changes.
*/
if (current_usn > msds_intid_struct->usn) {
/* oups something has changed, someone/something
* else is modifying or has modified the schema
* we'd better check this intid is the database directly
*/
DEBUG(2, ("Schema has changed, searching the database for the unicity of %d\n",
msds_intid));
ret = dsdb_module_search(ac->module, ac,
&ldb_res,
schema_dn, LDB_SCOPE_ONELEVEL, NULL,
DSDB_FLAG_NEXT_MODULE,
ac->req,
"(msDS-IntId=%d)", msds_intid);
if (ret != LDB_SUCCESS) {
ldb_debug_set(ldb, LDB_DEBUG_ERROR,
__location__": Searching for msDS-IntId=%d failed - %s\n",
msds_intid,
ldb_errstring(ldb));
return ldb_operr(ldb);
}
id_exists = (ldb_res->count > 0);
talloc_free(ldb_res);
} else {
id_exists = 0;
}
} while(id_exists);
msds_intid_struct->msds_intid = msds_intid;
ldb_set_opaque(ldb, SAMLDB_MSDS_INTID_OPAQUE, msds_intid_struct);
return samdb_msg_add_int(ldb, ac->msg, ac->msg, "msDS-IntId",
msds_intid);
}
| Bypass | 0 | static int samldb_add_handle_msDS_IntId(struct samldb_ctx *ac)
{
int ret;
bool id_exists;
uint32_t msds_intid;
int32_t system_flags;
struct ldb_context *ldb;
struct ldb_result *ldb_res;
struct ldb_dn *schema_dn;
struct samldb_msds_intid_persistant *msds_intid_struct;
struct dsdb_schema *schema;
ldb = ldb_module_get_ctx(ac->module);
schema_dn = ldb_get_schema_basedn(ldb);
/* replicated update should always go through */
if (ldb_request_get_control(ac->req,
DSDB_CONTROL_REPLICATED_UPDATE_OID)) {
return LDB_SUCCESS;
}
/* msDS-IntId is handled by system and should never be
* passed by clients */
if (ldb_msg_find_element(ac->msg, "msDS-IntId")) {
return LDB_ERR_UNWILLING_TO_PERFORM;
}
/* do not generate msDS-IntId if Relax control is passed */
if (ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
return LDB_SUCCESS;
}
/* check Functional Level */
if (dsdb_functional_level(ldb) < DS_DOMAIN_FUNCTION_2003) {
return LDB_SUCCESS;
}
/* check systemFlags for SCHEMA_BASE_OBJECT flag */
system_flags = ldb_msg_find_attr_as_int(ac->msg, "systemFlags", 0);
if (system_flags & SYSTEM_FLAG_SCHEMA_BASE_OBJECT) {
return LDB_SUCCESS;
}
schema = dsdb_get_schema(ldb, NULL);
if (!schema) {
ldb_debug_set(ldb, LDB_DEBUG_FATAL,
"samldb_schema_info_update: no dsdb_schema loaded");
DEBUG(0,(__location__ ": %s\n", ldb_errstring(ldb)));
return ldb_operr(ldb);
}
msds_intid_struct = (struct samldb_msds_intid_persistant*) ldb_get_opaque(ldb, SAMLDB_MSDS_INTID_OPAQUE);
if (!msds_intid_struct) {
msds_intid_struct = talloc(ldb, struct samldb_msds_intid_persistant);
/* Generate new value for msDs-IntId
* Value should be in 0x80000000..0xBFFFFFFF range */
msds_intid = generate_random() % 0X3FFFFFFF;
msds_intid += 0x80000000;
msds_intid_struct->msds_intid = msds_intid;
msds_intid_struct->usn = schema->loaded_usn;
DEBUG(2, ("No samldb_msds_intid_persistant struct, allocating a new one\n"));
} else {
msds_intid = msds_intid_struct->msds_intid;
}
/* probe id values until unique one is found */
do {
uint64_t current_usn;
msds_intid++;
if (msds_intid > 0xBFFFFFFF) {
msds_intid = 0x80000001;
}
/*
* Alternative strategy to a costly (even indexed search) to the
* database.
* We search in the schema if we have already this intid (using dsdb_attribute_by_attributeID_id because
* in the range 0x80000000 0xBFFFFFFFF, attributeID is a DSDB_ATTID_TYPE_INTID).
* If so generate another random value.
* If not check if the highest USN in the database for the schema partition is the
* one that we know.
* If so it means that's only this ldb context that is touching the schema in the database.
* If not it means that's someone else has modified the database while we are doing our changes too
* (this case should be very bery rare) in order to be sure do the search in the database.
*/
if (dsdb_attribute_by_attributeID_id(schema, msds_intid)) {
msds_intid = generate_random() % 0X3FFFFFFF;
msds_intid += 0x80000000;
continue;
}
ret = dsdb_module_load_partition_usn(ac->module, schema_dn,
¤t_usn, NULL, NULL);
if (ret != LDB_SUCCESS) {
ldb_debug_set(ldb, LDB_DEBUG_ERROR,
__location__": Searching for schema USN failed: %s\n",
ldb_errstring(ldb));
return ldb_operr(ldb);
}
/* current_usn can be lesser than msds_intid_struct-> if there is
* uncommited changes.
*/
if (current_usn > msds_intid_struct->usn) {
/* oups something has changed, someone/something
* else is modifying or has modified the schema
* we'd better check this intid is the database directly
*/
DEBUG(2, ("Schema has changed, searching the database for the unicity of %d\n",
msds_intid));
ret = dsdb_module_search(ac->module, ac,
&ldb_res,
schema_dn, LDB_SCOPE_ONELEVEL, NULL,
DSDB_FLAG_NEXT_MODULE,
ac->req,
"(msDS-IntId=%d)", msds_intid);
if (ret != LDB_SUCCESS) {
ldb_debug_set(ldb, LDB_DEBUG_ERROR,
__location__": Searching for msDS-IntId=%d failed - %s\n",
msds_intid,
ldb_errstring(ldb));
return ldb_operr(ldb);
}
id_exists = (ldb_res->count > 0);
talloc_free(ldb_res);
} else {
id_exists = 0;
}
} while(id_exists);
msds_intid_struct->msds_intid = msds_intid;
ldb_set_opaque(ldb, SAMLDB_MSDS_INTID_OPAQUE, msds_intid_struct);
return samdb_msg_add_int(ldb, ac->msg, ac->msg, "msDS-IntId",
msds_intid);
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
4 | static int samldb_add_step(struct samldb_ctx *ac, samldb_step_fn_t fn)
{
struct samldb_step *step, *stepper;
step = talloc_zero(ac, struct samldb_step);
if (step == NULL) {
return ldb_oom(ldb_module_get_ctx(ac->module));
}
step->fn = fn;
if (ac->steps == NULL) {
ac->steps = step;
ac->curstep = step;
} else {
if (ac->curstep == NULL)
return ldb_operr(ldb_module_get_ctx(ac->module));
for (stepper = ac->curstep; stepper->next != NULL;
stepper = stepper->next);
stepper->next = step;
}
return LDB_SUCCESS;
}
| Bypass | 0 | static int samldb_add_step(struct samldb_ctx *ac, samldb_step_fn_t fn)
{
struct samldb_step *step, *stepper;
step = talloc_zero(ac, struct samldb_step);
if (step == NULL) {
return ldb_oom(ldb_module_get_ctx(ac->module));
}
step->fn = fn;
if (ac->steps == NULL) {
ac->steps = step;
ac->curstep = step;
} else {
if (ac->curstep == NULL)
return ldb_operr(ldb_module_get_ctx(ac->module));
for (stepper = ac->curstep; stepper->next != NULL;
stepper = stepper->next);
stepper->next = step;
}
return LDB_SUCCESS;
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
5 | static int samldb_check_sAMAccountName(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const char *name;
int ret;
struct ldb_result *res;
const char * const noattrs[] = { NULL };
if (ldb_msg_find_element(ac->msg, "sAMAccountName") == NULL) {
ret = samldb_generate_sAMAccountName(ldb, ac->msg);
if (ret != LDB_SUCCESS) {
return ret;
}
}
name = ldb_msg_find_attr_as_string(ac->msg, "sAMAccountName", NULL);
if (name == NULL) {
/* The "sAMAccountName" cannot be nothing */
ldb_set_errstring(ldb,
"samldb: Empty account names aren't allowed!");
return LDB_ERR_CONSTRAINT_VIOLATION;
}
ret = dsdb_module_search(ac->module, ac, &res,
ldb_get_default_basedn(ldb), LDB_SCOPE_SUBTREE, noattrs,
DSDB_FLAG_NEXT_MODULE,
ac->req,
"(sAMAccountName=%s)",
ldb_binary_encode_string(ac, name));
if (ret != LDB_SUCCESS) {
return ret;
}
if (res->count != 0) {
ldb_asprintf_errstring(ldb,
"samldb: Account name (sAMAccountName) '%s' already in use!",
name);
talloc_free(res);
return LDB_ERR_ENTRY_ALREADY_EXISTS;
}
talloc_free(res);
return samldb_next_step(ac);
}
| Bypass | 0 | static int samldb_check_sAMAccountName(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const char *name;
int ret;
struct ldb_result *res;
const char * const noattrs[] = { NULL };
if (ldb_msg_find_element(ac->msg, "sAMAccountName") == NULL) {
ret = samldb_generate_sAMAccountName(ldb, ac->msg);
if (ret != LDB_SUCCESS) {
return ret;
}
}
name = ldb_msg_find_attr_as_string(ac->msg, "sAMAccountName", NULL);
if (name == NULL) {
/* The "sAMAccountName" cannot be nothing */
ldb_set_errstring(ldb,
"samldb: Empty account names aren't allowed!");
return LDB_ERR_CONSTRAINT_VIOLATION;
}
ret = dsdb_module_search(ac->module, ac, &res,
ldb_get_default_basedn(ldb), LDB_SCOPE_SUBTREE, noattrs,
DSDB_FLAG_NEXT_MODULE,
ac->req,
"(sAMAccountName=%s)",
ldb_binary_encode_string(ac, name));
if (ret != LDB_SUCCESS) {
return ret;
}
if (res->count != 0) {
ldb_asprintf_errstring(ldb,
"samldb: Account name (sAMAccountName) '%s' already in use!",
name);
talloc_free(res);
return LDB_ERR_ENTRY_ALREADY_EXISTS;
}
talloc_free(res);
return samldb_next_step(ac);
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
6 | static int samldb_check_user_account_control_invariants(struct samldb_ctx *ac,
uint32_t user_account_control)
{
int i, ret = 0;
bool need_check = false;
const struct uac_to_guid {
uint32_t uac;
bool never;
uint32_t needs;
uint32_t not_with;
const char *error_string;
} map[] = {
{
.uac = UF_TEMP_DUPLICATE_ACCOUNT,
.never = true,
.error_string = "Updating the UF_TEMP_DUPLICATE_ACCOUNT flag is never allowed"
},
{
.uac = UF_PARTIAL_SECRETS_ACCOUNT,
.needs = UF_WORKSTATION_TRUST_ACCOUNT,
.error_string = "Setting UF_PARTIAL_SECRETS_ACCOUNT only permitted with UF_WORKSTATION_TRUST_ACCOUNT"
},
{
.uac = UF_TRUSTED_FOR_DELEGATION,
.not_with = UF_PARTIAL_SECRETS_ACCOUNT,
.error_string = "Setting UF_TRUSTED_FOR_DELEGATION not allowed with UF_PARTIAL_SECRETS_ACCOUNT"
},
{
.uac = UF_NORMAL_ACCOUNT,
.not_with = UF_ACCOUNT_TYPE_MASK & ~UF_NORMAL_ACCOUNT,
.error_string = "Setting more than one account type not permitted"
},
{
.uac = UF_WORKSTATION_TRUST_ACCOUNT,
.not_with = UF_ACCOUNT_TYPE_MASK & ~UF_WORKSTATION_TRUST_ACCOUNT,
.error_string = "Setting more than one account type not permitted"
},
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.not_with = UF_ACCOUNT_TYPE_MASK & ~UF_INTERDOMAIN_TRUST_ACCOUNT,
.error_string = "Setting more than one account type not permitted"
},
{
.uac = UF_SERVER_TRUST_ACCOUNT,
.not_with = UF_ACCOUNT_TYPE_MASK & ~UF_SERVER_TRUST_ACCOUNT,
.error_string = "Setting more than one account type not permitted"
},
{
.uac = UF_TRUSTED_FOR_DELEGATION,
.not_with = UF_PARTIAL_SECRETS_ACCOUNT,
.error_string = "Setting UF_TRUSTED_FOR_DELEGATION not allowed with UF_PARTIAL_SECRETS_ACCOUNT"
}
};
for (i = 0; i < ARRAY_SIZE(map); i++) {
if (user_account_control & map[i].uac) {
need_check = true;
break;
}
}
if (need_check == false) {
return LDB_SUCCESS;
}
for (i = 0; i < ARRAY_SIZE(map); i++) {
uint32_t this_uac = user_account_control & map[i].uac;
if (this_uac != 0) {
if (map[i].never) {
ret = LDB_ERR_OTHER;
break;
} else if (map[i].needs != 0) {
if ((map[i].needs & user_account_control) == 0) {
ret = LDB_ERR_OTHER;
break;
}
} else if (map[i].not_with != 0) {
if ((map[i].not_with & user_account_control) != 0) {
ret = LDB_ERR_OTHER;
break;
}
}
}
}
if (ret != LDB_SUCCESS) {
switch (ac->req->operation) {
case LDB_ADD:
ldb_asprintf_errstring(ldb_module_get_ctx(ac->module),
"Failed to add %s: %s",
ldb_dn_get_linearized(ac->msg->dn),
map[i].error_string);
break;
case LDB_MODIFY:
ldb_asprintf_errstring(ldb_module_get_ctx(ac->module),
"Failed to modify %s: %s",
ldb_dn_get_linearized(ac->msg->dn),
map[i].error_string);
break;
default:
return ldb_module_operr(ac->module);
}
}
return ret;
}
| Bypass | 0 | static int samldb_check_user_account_control_invariants(struct samldb_ctx *ac,
uint32_t user_account_control)
{
int i, ret = 0;
bool need_check = false;
const struct uac_to_guid {
uint32_t uac;
bool never;
uint32_t needs;
uint32_t not_with;
const char *error_string;
} map[] = {
{
.uac = UF_TEMP_DUPLICATE_ACCOUNT,
.never = true,
.error_string = "Updating the UF_TEMP_DUPLICATE_ACCOUNT flag is never allowed"
},
{
.uac = UF_PARTIAL_SECRETS_ACCOUNT,
.needs = UF_WORKSTATION_TRUST_ACCOUNT,
.error_string = "Setting UF_PARTIAL_SECRETS_ACCOUNT only permitted with UF_WORKSTATION_TRUST_ACCOUNT"
},
{
.uac = UF_TRUSTED_FOR_DELEGATION,
.not_with = UF_PARTIAL_SECRETS_ACCOUNT,
.error_string = "Setting UF_TRUSTED_FOR_DELEGATION not allowed with UF_PARTIAL_SECRETS_ACCOUNT"
},
{
.uac = UF_NORMAL_ACCOUNT,
.not_with = UF_ACCOUNT_TYPE_MASK & ~UF_NORMAL_ACCOUNT,
.error_string = "Setting more than one account type not permitted"
},
{
.uac = UF_WORKSTATION_TRUST_ACCOUNT,
.not_with = UF_ACCOUNT_TYPE_MASK & ~UF_WORKSTATION_TRUST_ACCOUNT,
.error_string = "Setting more than one account type not permitted"
},
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.not_with = UF_ACCOUNT_TYPE_MASK & ~UF_INTERDOMAIN_TRUST_ACCOUNT,
.error_string = "Setting more than one account type not permitted"
},
{
.uac = UF_SERVER_TRUST_ACCOUNT,
.not_with = UF_ACCOUNT_TYPE_MASK & ~UF_SERVER_TRUST_ACCOUNT,
.error_string = "Setting more than one account type not permitted"
},
{
.uac = UF_TRUSTED_FOR_DELEGATION,
.not_with = UF_PARTIAL_SECRETS_ACCOUNT,
.error_string = "Setting UF_TRUSTED_FOR_DELEGATION not allowed with UF_PARTIAL_SECRETS_ACCOUNT"
}
};
for (i = 0; i < ARRAY_SIZE(map); i++) {
if (user_account_control & map[i].uac) {
need_check = true;
break;
}
}
if (need_check == false) {
return LDB_SUCCESS;
}
for (i = 0; i < ARRAY_SIZE(map); i++) {
uint32_t this_uac = user_account_control & map[i].uac;
if (this_uac != 0) {
if (map[i].never) {
ret = LDB_ERR_OTHER;
break;
} else if (map[i].needs != 0) {
if ((map[i].needs & user_account_control) == 0) {
ret = LDB_ERR_OTHER;
break;
}
} else if (map[i].not_with != 0) {
if ((map[i].not_with & user_account_control) != 0) {
ret = LDB_ERR_OTHER;
break;
}
}
}
}
if (ret != LDB_SUCCESS) {
switch (ac->req->operation) {
case LDB_ADD:
ldb_asprintf_errstring(ldb_module_get_ctx(ac->module),
"Failed to add %s: %s",
ldb_dn_get_linearized(ac->msg->dn),
map[i].error_string);
break;
case LDB_MODIFY:
ldb_asprintf_errstring(ldb_module_get_ctx(ac->module),
"Failed to modify %s: %s",
ldb_dn_get_linearized(ac->msg->dn),
map[i].error_string);
break;
default:
return ldb_module_operr(ac->module);
}
}
return ret;
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
7 | static struct samldb_ctx *samldb_ctx_init(struct ldb_module *module,
struct ldb_request *req)
{
struct ldb_context *ldb;
struct samldb_ctx *ac;
ldb = ldb_module_get_ctx(module);
ac = talloc_zero(req, struct samldb_ctx);
if (ac == NULL) {
ldb_oom(ldb);
return NULL;
}
ac->module = module;
ac->req = req;
return ac;
}
| Bypass | 0 | static struct samldb_ctx *samldb_ctx_init(struct ldb_module *module,
struct ldb_request *req)
{
struct ldb_context *ldb;
struct samldb_ctx *ac;
ldb = ldb_module_get_ctx(module);
ac = talloc_zero(req, struct samldb_ctx);
if (ac == NULL) {
ldb_oom(ldb);
return NULL;
}
ac->module = module;
ac->req = req;
return ac;
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
8 | static int samldb_fill_foreignSecurityPrincipal_object(struct samldb_ctx *ac)
{
struct ldb_context *ldb;
const struct ldb_val *rdn_value;
struct dom_sid *sid;
int ret;
ldb = ldb_module_get_ctx(ac->module);
sid = samdb_result_dom_sid(ac->msg, ac->msg, "objectSid");
if (sid == NULL) {
rdn_value = ldb_dn_get_rdn_val(ac->msg->dn);
if (rdn_value == NULL) {
return ldb_operr(ldb);
}
sid = dom_sid_parse_talloc(ac->msg,
(const char *)rdn_value->data);
if (sid == NULL) {
ldb_set_errstring(ldb,
"samldb: No valid SID found in ForeignSecurityPrincipal CN!");
return LDB_ERR_CONSTRAINT_VIOLATION;
}
if (! samldb_msg_add_sid(ac->msg, "objectSid", sid)) {
return ldb_operr(ldb);
}
}
/* finally proceed with adding the entry */
ret = samldb_add_step(ac, samldb_add_entry);
if (ret != LDB_SUCCESS) return ret;
return samldb_first_step(ac);
}
| Bypass | 0 | static int samldb_fill_foreignSecurityPrincipal_object(struct samldb_ctx *ac)
{
struct ldb_context *ldb;
const struct ldb_val *rdn_value;
struct dom_sid *sid;
int ret;
ldb = ldb_module_get_ctx(ac->module);
sid = samdb_result_dom_sid(ac->msg, ac->msg, "objectSid");
if (sid == NULL) {
rdn_value = ldb_dn_get_rdn_val(ac->msg->dn);
if (rdn_value == NULL) {
return ldb_operr(ldb);
}
sid = dom_sid_parse_talloc(ac->msg,
(const char *)rdn_value->data);
if (sid == NULL) {
ldb_set_errstring(ldb,
"samldb: No valid SID found in ForeignSecurityPrincipal CN!");
return LDB_ERR_CONSTRAINT_VIOLATION;
}
if (! samldb_msg_add_sid(ac->msg, "objectSid", sid)) {
return ldb_operr(ldb);
}
}
/* finally proceed with adding the entry */
ret = samldb_add_step(ac, samldb_add_entry);
if (ret != LDB_SUCCESS) return ret;
return samldb_first_step(ac);
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
9 | static int samldb_find_for_defaultObjectCategory(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
struct ldb_result *res;
const char * const no_attrs[] = { NULL };
int ret;
ac->res_dn = NULL;
ret = dsdb_module_search(ac->module, ac, &res,
ac->dn, LDB_SCOPE_BASE, no_attrs,
DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT
| DSDB_FLAG_NEXT_MODULE,
ac->req,
"(objectClass=classSchema)");
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
/* Don't be pricky when the DN doesn't exist if we have the */
/* RELAX control specified */
if (ldb_request_get_control(ac->req,
LDB_CONTROL_RELAX_OID) == NULL) {
ldb_set_errstring(ldb,
"samldb_find_defaultObjectCategory: "
"Invalid DN for 'defaultObjectCategory'!");
return LDB_ERR_CONSTRAINT_VIOLATION;
}
}
if ((ret != LDB_ERR_NO_SUCH_OBJECT) && (ret != LDB_SUCCESS)) {
return ret;
}
if (ret == LDB_SUCCESS) {
/* ensure the defaultObjectCategory has a full GUID */
struct ldb_message *m;
m = ldb_msg_new(ac->msg);
if (m == NULL) {
return ldb_oom(ldb);
}
m->dn = ac->msg->dn;
if (ldb_msg_add_string(m, "defaultObjectCategory",
ldb_dn_get_extended_linearized(m, res->msgs[0]->dn, 1)) !=
LDB_SUCCESS) {
return ldb_oom(ldb);
}
m->elements[0].flags = LDB_FLAG_MOD_REPLACE;
ret = dsdb_module_modify(ac->module, m,
DSDB_FLAG_NEXT_MODULE,
ac->req);
if (ret != LDB_SUCCESS) {
return ret;
}
}
ac->res_dn = ac->dn;
return samldb_next_step(ac);
}
| Bypass | 0 | static int samldb_find_for_defaultObjectCategory(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
struct ldb_result *res;
const char * const no_attrs[] = { NULL };
int ret;
ac->res_dn = NULL;
ret = dsdb_module_search(ac->module, ac, &res,
ac->dn, LDB_SCOPE_BASE, no_attrs,
DSDB_SEARCH_SHOW_DN_IN_STORAGE_FORMAT
| DSDB_FLAG_NEXT_MODULE,
ac->req,
"(objectClass=classSchema)");
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
/* Don't be pricky when the DN doesn't exist if we have the */
/* RELAX control specified */
if (ldb_request_get_control(ac->req,
LDB_CONTROL_RELAX_OID) == NULL) {
ldb_set_errstring(ldb,
"samldb_find_defaultObjectCategory: "
"Invalid DN for 'defaultObjectCategory'!");
return LDB_ERR_CONSTRAINT_VIOLATION;
}
}
if ((ret != LDB_ERR_NO_SUCH_OBJECT) && (ret != LDB_SUCCESS)) {
return ret;
}
if (ret == LDB_SUCCESS) {
/* ensure the defaultObjectCategory has a full GUID */
struct ldb_message *m;
m = ldb_msg_new(ac->msg);
if (m == NULL) {
return ldb_oom(ldb);
}
m->dn = ac->msg->dn;
if (ldb_msg_add_string(m, "defaultObjectCategory",
ldb_dn_get_extended_linearized(m, res->msgs[0]->dn, 1)) !=
LDB_SUCCESS) {
return ldb_oom(ldb);
}
m->elements[0].flags = LDB_FLAG_MOD_REPLACE;
ret = dsdb_module_modify(ac->module, m,
DSDB_FLAG_NEXT_MODULE,
ac->req);
if (ret != LDB_SUCCESS) {
return ret;
}
}
ac->res_dn = ac->dn;
return samldb_next_step(ac);
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
10 | static bool samldb_krbtgtnumber_available(struct samldb_ctx *ac,
uint32_t krbtgt_number)
{
TALLOC_CTX *tmp_ctx = talloc_new(ac);
struct ldb_result *res;
const char * const no_attrs[] = { NULL };
int ret;
ret = dsdb_module_search(ac->module, tmp_ctx, &res,
ldb_get_default_basedn(ldb_module_get_ctx(ac->module)),
LDB_SCOPE_SUBTREE, no_attrs,
DSDB_FLAG_NEXT_MODULE,
ac->req,
"(msDC-SecondaryKrbTgtNumber=%u)",
krbtgt_number);
if (ret == LDB_SUCCESS && res->count == 0) {
talloc_free(tmp_ctx);
return true;
}
talloc_free(tmp_ctx);
return false;
}
| Bypass | 0 | static bool samldb_krbtgtnumber_available(struct samldb_ctx *ac,
uint32_t krbtgt_number)
{
TALLOC_CTX *tmp_ctx = talloc_new(ac);
struct ldb_result *res;
const char * const no_attrs[] = { NULL };
int ret;
ret = dsdb_module_search(ac->module, tmp_ctx, &res,
ldb_get_default_basedn(ldb_module_get_ctx(ac->module)),
LDB_SCOPE_SUBTREE, no_attrs,
DSDB_FLAG_NEXT_MODULE,
ac->req,
"(msDC-SecondaryKrbTgtNumber=%u)",
krbtgt_number);
if (ret == LDB_SUCCESS && res->count == 0) {
talloc_free(tmp_ctx);
return true;
}
talloc_free(tmp_ctx);
return false;
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
11 | static int samldb_next_step(struct samldb_ctx *ac)
{
if (ac->curstep->next) {
ac->curstep = ac->curstep->next;
return ac->curstep->fn(ac);
}
/* We exit the samldb module here. If someone set an "ares" to forward
* controls and response back to the caller, use them. */
if (ac->ares) {
return ldb_module_done(ac->req, ac->ares->controls,
ac->ares->response, LDB_SUCCESS);
} else {
return ldb_module_done(ac->req, NULL, NULL, LDB_SUCCESS);
}
}
| Bypass | 0 | static int samldb_next_step(struct samldb_ctx *ac)
{
if (ac->curstep->next) {
ac->curstep = ac->curstep->next;
return ac->curstep->fn(ac);
}
/* We exit the samldb module here. If someone set an "ares" to forward
* controls and response back to the caller, use them. */
if (ac->ares) {
return ldb_module_done(ac->req, ac->ares->controls,
ac->ares->response, LDB_SUCCESS);
} else {
return ldb_module_done(ac->req, NULL, NULL, LDB_SUCCESS);
}
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
12 | static int samldb_objectclass_trigger(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
void *skip_allocate_sids = ldb_get_opaque(ldb,
"skip_allocate_sids");
struct ldb_message_element *el, *el2;
struct dom_sid *sid;
int ret;
/* make sure that "sAMAccountType" is not specified */
el = ldb_msg_find_element(ac->msg, "sAMAccountType");
if (el != NULL) {
ldb_set_errstring(ldb,
"samldb: sAMAccountType must not be specified!");
return LDB_ERR_UNWILLING_TO_PERFORM;
}
/* Step 1: objectSid assignment */
/* Don't allow the objectSid to be changed. But beside the RELAX
* control we have also to guarantee that it can always be set with
* SYSTEM permissions. This is needed for the "samba3sam" backend. */
sid = samdb_result_dom_sid(ac, ac->msg, "objectSid");
if ((sid != NULL) && (!dsdb_module_am_system(ac->module)) &&
(ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID) == NULL)) {
ldb_set_errstring(ldb,
"samldb: objectSid must not be specified!");
return LDB_ERR_UNWILLING_TO_PERFORM;
}
/* but generate a new SID when we do have an add operations */
if ((sid == NULL) && (ac->req->operation == LDB_ADD) && !skip_allocate_sids) {
ret = samldb_add_step(ac, samldb_allocate_sid);
if (ret != LDB_SUCCESS) return ret;
}
switch(ac->type) {
case SAMLDB_TYPE_USER: {
bool uac_generated = false, uac_add_flags = false;
/* Step 1.2: Default values */
ret = dsdb_user_obj_set_defaults(ldb, ac->msg);
if (ret != LDB_SUCCESS) return ret;
/* On add operations we might need to generate a
* "userAccountControl" (if it isn't specified). */
el = ldb_msg_find_element(ac->msg, "userAccountControl");
if ((el == NULL) && (ac->req->operation == LDB_ADD)) {
ret = samdb_msg_set_uint(ldb, ac->msg, ac->msg,
"userAccountControl",
UF_NORMAL_ACCOUNT);
if (ret != LDB_SUCCESS) {
return ret;
}
uac_generated = true;
uac_add_flags = true;
}
el = ldb_msg_find_element(ac->msg, "userAccountControl");
if (el != NULL) {
uint32_t user_account_control;
/* Step 1.3: "userAccountControl" -> "sAMAccountType" mapping */
user_account_control = ldb_msg_find_attr_as_uint(ac->msg,
"userAccountControl",
0);
/*
* "userAccountControl" = 0 or missing one of
* the types means "UF_NORMAL_ACCOUNT". See
* MS-SAMR 3.1.1.8.10 point 8
*/
if ((user_account_control & UF_ACCOUNT_TYPE_MASK) == 0) {
user_account_control = UF_NORMAL_ACCOUNT | user_account_control;
uac_generated = true;
}
/*
* As per MS-SAMR 3.1.1.8.10 these flags have not to be set
*/
if ((user_account_control & UF_LOCKOUT) != 0) {
user_account_control &= ~UF_LOCKOUT;
uac_generated = true;
}
if ((user_account_control & UF_PASSWORD_EXPIRED) != 0) {
user_account_control &= ~UF_PASSWORD_EXPIRED;
uac_generated = true;
}
ret = samldb_check_user_account_control_rules(ac, NULL,
user_account_control, 0);
if (ret != LDB_SUCCESS) {
return ret;
}
/* Workstation and (read-only) DC objects do need objectclass "computer" */
if ((samdb_find_attribute(ldb, ac->msg,
"objectclass", "computer") == NULL) &&
(user_account_control &
(UF_SERVER_TRUST_ACCOUNT | UF_WORKSTATION_TRUST_ACCOUNT))) {
ldb_set_errstring(ldb,
"samldb: Requested account type does need objectclass 'computer'!");
return LDB_ERR_OBJECT_CLASS_VIOLATION;
}
/* add "sAMAccountType" attribute */
ret = dsdb_user_obj_set_account_type(ldb, ac->msg, user_account_control, NULL);
if (ret != LDB_SUCCESS) {
return ret;
}
/* "isCriticalSystemObject" might be set */
if (user_account_control &
(UF_SERVER_TRUST_ACCOUNT | UF_PARTIAL_SECRETS_ACCOUNT)) {
ret = ldb_msg_add_string(ac->msg, "isCriticalSystemObject",
"TRUE");
if (ret != LDB_SUCCESS) {
return ret;
}
el2 = ldb_msg_find_element(ac->msg,
"isCriticalSystemObject");
el2->flags = LDB_FLAG_MOD_REPLACE;
} else if (user_account_control & UF_WORKSTATION_TRUST_ACCOUNT) {
ret = ldb_msg_add_string(ac->msg, "isCriticalSystemObject",
"FALSE");
if (ret != LDB_SUCCESS) {
return ret;
}
el2 = ldb_msg_find_element(ac->msg,
"isCriticalSystemObject");
el2->flags = LDB_FLAG_MOD_REPLACE;
}
/* Step 1.4: "userAccountControl" -> "primaryGroupID" mapping */
if (!ldb_msg_find_element(ac->msg, "primaryGroupID")) {
uint32_t rid;
ret = dsdb_user_obj_set_primary_group_id(ldb, ac->msg, user_account_control, &rid);
if (ret != LDB_SUCCESS) {
return ret;
}
/*
* Older AD deployments don't know about the
* RODC group
*/
if (rid == DOMAIN_RID_READONLY_DCS) {
ret = samldb_prim_group_tester(ac, rid);
if (ret != LDB_SUCCESS) {
return ret;
}
}
}
/* Step 1.5: Add additional flags when needed */
/* Obviously this is done when the "userAccountControl"
* has been generated here (tested against Windows
* Server) */
if (uac_generated) {
if (uac_add_flags) {
user_account_control |= UF_ACCOUNTDISABLE;
user_account_control |= UF_PASSWD_NOTREQD;
}
ret = samdb_msg_set_uint(ldb, ac->msg, ac->msg,
"userAccountControl",
user_account_control);
if (ret != LDB_SUCCESS) {
return ret;
}
}
}
break;
}
case SAMLDB_TYPE_GROUP: {
const char *tempstr;
/* Step 2.2: Default values */
tempstr = talloc_asprintf(ac->msg, "%d",
GTYPE_SECURITY_GLOBAL_GROUP);
if (tempstr == NULL) return ldb_operr(ldb);
ret = samdb_find_or_add_attribute(ldb, ac->msg,
"groupType", tempstr);
if (ret != LDB_SUCCESS) return ret;
/* Step 2.3: "groupType" -> "sAMAccountType" */
el = ldb_msg_find_element(ac->msg, "groupType");
if (el != NULL) {
uint32_t group_type, account_type;
group_type = ldb_msg_find_attr_as_uint(ac->msg,
"groupType", 0);
/* The creation of builtin groups requires the
* RELAX control */
if (group_type == GTYPE_SECURITY_BUILTIN_LOCAL_GROUP) {
if (ldb_request_get_control(ac->req,
LDB_CONTROL_RELAX_OID) == NULL) {
return LDB_ERR_UNWILLING_TO_PERFORM;
}
}
account_type = ds_gtype2atype(group_type);
if (account_type == 0) {
ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
return LDB_ERR_UNWILLING_TO_PERFORM;
}
ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
"sAMAccountType",
account_type);
if (ret != LDB_SUCCESS) {
return ret;
}
el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
el2->flags = LDB_FLAG_MOD_REPLACE;
}
break;
}
default:
ldb_asprintf_errstring(ldb,
"Invalid entry type!");
return LDB_ERR_OPERATIONS_ERROR;
break;
}
return LDB_SUCCESS;
}
| Bypass | 0 | static int samldb_objectclass_trigger(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
void *skip_allocate_sids = ldb_get_opaque(ldb,
"skip_allocate_sids");
struct ldb_message_element *el, *el2;
struct dom_sid *sid;
int ret;
/* make sure that "sAMAccountType" is not specified */
el = ldb_msg_find_element(ac->msg, "sAMAccountType");
if (el != NULL) {
ldb_set_errstring(ldb,
"samldb: sAMAccountType must not be specified!");
return LDB_ERR_UNWILLING_TO_PERFORM;
}
/* Step 1: objectSid assignment */
/* Don't allow the objectSid to be changed. But beside the RELAX
* control we have also to guarantee that it can always be set with
* SYSTEM permissions. This is needed for the "samba3sam" backend. */
sid = samdb_result_dom_sid(ac, ac->msg, "objectSid");
if ((sid != NULL) && (!dsdb_module_am_system(ac->module)) &&
(ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID) == NULL)) {
ldb_set_errstring(ldb,
"samldb: objectSid must not be specified!");
return LDB_ERR_UNWILLING_TO_PERFORM;
}
/* but generate a new SID when we do have an add operations */
if ((sid == NULL) && (ac->req->operation == LDB_ADD) && !skip_allocate_sids) {
ret = samldb_add_step(ac, samldb_allocate_sid);
if (ret != LDB_SUCCESS) return ret;
}
switch(ac->type) {
case SAMLDB_TYPE_USER: {
bool uac_generated = false, uac_add_flags = false;
/* Step 1.2: Default values */
ret = dsdb_user_obj_set_defaults(ldb, ac->msg);
if (ret != LDB_SUCCESS) return ret;
/* On add operations we might need to generate a
* "userAccountControl" (if it isn't specified). */
el = ldb_msg_find_element(ac->msg, "userAccountControl");
if ((el == NULL) && (ac->req->operation == LDB_ADD)) {
ret = samdb_msg_set_uint(ldb, ac->msg, ac->msg,
"userAccountControl",
UF_NORMAL_ACCOUNT);
if (ret != LDB_SUCCESS) {
return ret;
}
uac_generated = true;
uac_add_flags = true;
}
el = ldb_msg_find_element(ac->msg, "userAccountControl");
if (el != NULL) {
uint32_t user_account_control;
/* Step 1.3: "userAccountControl" -> "sAMAccountType" mapping */
user_account_control = ldb_msg_find_attr_as_uint(ac->msg,
"userAccountControl",
0);
/*
* "userAccountControl" = 0 or missing one of
* the types means "UF_NORMAL_ACCOUNT". See
* MS-SAMR 3.1.1.8.10 point 8
*/
if ((user_account_control & UF_ACCOUNT_TYPE_MASK) == 0) {
user_account_control = UF_NORMAL_ACCOUNT | user_account_control;
uac_generated = true;
}
/*
* As per MS-SAMR 3.1.1.8.10 these flags have not to be set
*/
if ((user_account_control & UF_LOCKOUT) != 0) {
user_account_control &= ~UF_LOCKOUT;
uac_generated = true;
}
if ((user_account_control & UF_PASSWORD_EXPIRED) != 0) {
user_account_control &= ~UF_PASSWORD_EXPIRED;
uac_generated = true;
}
ret = samldb_check_user_account_control_rules(ac, NULL,
user_account_control, 0);
if (ret != LDB_SUCCESS) {
return ret;
}
/* Workstation and (read-only) DC objects do need objectclass "computer" */
if ((samdb_find_attribute(ldb, ac->msg,
"objectclass", "computer") == NULL) &&
(user_account_control &
(UF_SERVER_TRUST_ACCOUNT | UF_WORKSTATION_TRUST_ACCOUNT))) {
ldb_set_errstring(ldb,
"samldb: Requested account type does need objectclass 'computer'!");
return LDB_ERR_OBJECT_CLASS_VIOLATION;
}
/* add "sAMAccountType" attribute */
ret = dsdb_user_obj_set_account_type(ldb, ac->msg, user_account_control, NULL);
if (ret != LDB_SUCCESS) {
return ret;
}
/* "isCriticalSystemObject" might be set */
if (user_account_control &
(UF_SERVER_TRUST_ACCOUNT | UF_PARTIAL_SECRETS_ACCOUNT)) {
ret = ldb_msg_add_string(ac->msg, "isCriticalSystemObject",
"TRUE");
if (ret != LDB_SUCCESS) {
return ret;
}
el2 = ldb_msg_find_element(ac->msg,
"isCriticalSystemObject");
el2->flags = LDB_FLAG_MOD_REPLACE;
} else if (user_account_control & UF_WORKSTATION_TRUST_ACCOUNT) {
ret = ldb_msg_add_string(ac->msg, "isCriticalSystemObject",
"FALSE");
if (ret != LDB_SUCCESS) {
return ret;
}
el2 = ldb_msg_find_element(ac->msg,
"isCriticalSystemObject");
el2->flags = LDB_FLAG_MOD_REPLACE;
}
/* Step 1.4: "userAccountControl" -> "primaryGroupID" mapping */
if (!ldb_msg_find_element(ac->msg, "primaryGroupID")) {
uint32_t rid;
ret = dsdb_user_obj_set_primary_group_id(ldb, ac->msg, user_account_control, &rid);
if (ret != LDB_SUCCESS) {
return ret;
}
/*
* Older AD deployments don't know about the
* RODC group
*/
if (rid == DOMAIN_RID_READONLY_DCS) {
ret = samldb_prim_group_tester(ac, rid);
if (ret != LDB_SUCCESS) {
return ret;
}
}
}
/* Step 1.5: Add additional flags when needed */
/* Obviously this is done when the "userAccountControl"
* has been generated here (tested against Windows
* Server) */
if (uac_generated) {
if (uac_add_flags) {
user_account_control |= UF_ACCOUNTDISABLE;
user_account_control |= UF_PASSWD_NOTREQD;
}
ret = samdb_msg_set_uint(ldb, ac->msg, ac->msg,
"userAccountControl",
user_account_control);
if (ret != LDB_SUCCESS) {
return ret;
}
}
}
break;
}
case SAMLDB_TYPE_GROUP: {
const char *tempstr;
/* Step 2.2: Default values */
tempstr = talloc_asprintf(ac->msg, "%d",
GTYPE_SECURITY_GLOBAL_GROUP);
if (tempstr == NULL) return ldb_operr(ldb);
ret = samdb_find_or_add_attribute(ldb, ac->msg,
"groupType", tempstr);
if (ret != LDB_SUCCESS) return ret;
/* Step 2.3: "groupType" -> "sAMAccountType" */
el = ldb_msg_find_element(ac->msg, "groupType");
if (el != NULL) {
uint32_t group_type, account_type;
group_type = ldb_msg_find_attr_as_uint(ac->msg,
"groupType", 0);
/* The creation of builtin groups requires the
* RELAX control */
if (group_type == GTYPE_SECURITY_BUILTIN_LOCAL_GROUP) {
if (ldb_request_get_control(ac->req,
LDB_CONTROL_RELAX_OID) == NULL) {
return LDB_ERR_UNWILLING_TO_PERFORM;
}
}
account_type = ds_gtype2atype(group_type);
if (account_type == 0) {
ldb_set_errstring(ldb, "samldb: Unrecognized account type!");
return LDB_ERR_UNWILLING_TO_PERFORM;
}
ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
"sAMAccountType",
account_type);
if (ret != LDB_SUCCESS) {
return ret;
}
el2 = ldb_msg_find_element(ac->msg, "sAMAccountType");
el2->flags = LDB_FLAG_MOD_REPLACE;
}
break;
}
default:
ldb_asprintf_errstring(ldb,
"Invalid entry type!");
return LDB_ERR_OPERATIONS_ERROR;
break;
}
return LDB_SUCCESS;
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
13 | static int samldb_prim_group_set(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
uint32_t rid;
rid = ldb_msg_find_attr_as_uint(ac->msg, "primaryGroupID", (uint32_t) -1);
if (rid == (uint32_t) -1) {
/* we aren't affected of any primary group set */
return LDB_SUCCESS;
} else if (!ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
ldb_set_errstring(ldb,
"The primary group isn't settable on add operations!");
return LDB_ERR_UNWILLING_TO_PERFORM;
}
return samldb_prim_group_tester(ac, rid);
}
| Bypass | 0 | static int samldb_prim_group_set(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
uint32_t rid;
rid = ldb_msg_find_attr_as_uint(ac->msg, "primaryGroupID", (uint32_t) -1);
if (rid == (uint32_t) -1) {
/* we aren't affected of any primary group set */
return LDB_SUCCESS;
} else if (!ldb_request_get_control(ac->req, LDB_CONTROL_RELAX_OID)) {
ldb_set_errstring(ldb,
"The primary group isn't settable on add operations!");
return LDB_ERR_UNWILLING_TO_PERFORM;
}
return samldb_prim_group_tester(ac, rid);
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
14 | static int samldb_prim_group_tester(struct samldb_ctx *ac, uint32_t rid)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
struct dom_sid *sid;
struct ldb_result *res;
int ret;
const char * const noattrs[] = { NULL };
sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), rid);
if (sid == NULL) {
return ldb_operr(ldb);
}
ret = dsdb_module_search(ac->module, ac, &res,
ldb_get_default_basedn(ldb),
LDB_SCOPE_SUBTREE,
noattrs, DSDB_FLAG_NEXT_MODULE,
ac->req,
"(objectSid=%s)",
ldap_encode_ndr_dom_sid(ac, sid));
if (ret != LDB_SUCCESS) {
return ret;
}
if (res->count != 1) {
talloc_free(res);
ldb_asprintf_errstring(ldb,
"Failed to find primary group with RID %u!",
rid);
return LDB_ERR_UNWILLING_TO_PERFORM;
}
talloc_free(res);
return LDB_SUCCESS;
}
| Bypass | 0 | static int samldb_prim_group_tester(struct samldb_ctx *ac, uint32_t rid)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
struct dom_sid *sid;
struct ldb_result *res;
int ret;
const char * const noattrs[] = { NULL };
sid = dom_sid_add_rid(ac, samdb_domain_sid(ldb), rid);
if (sid == NULL) {
return ldb_operr(ldb);
}
ret = dsdb_module_search(ac->module, ac, &res,
ldb_get_default_basedn(ldb),
LDB_SCOPE_SUBTREE,
noattrs, DSDB_FLAG_NEXT_MODULE,
ac->req,
"(objectSid=%s)",
ldap_encode_ndr_dom_sid(ac, sid));
if (ret != LDB_SUCCESS) {
return ret;
}
if (res->count != 1) {
talloc_free(res);
ldb_asprintf_errstring(ldb,
"Failed to find primary group with RID %u!",
rid);
return LDB_ERR_UNWILLING_TO_PERFORM;
}
talloc_free(res);
return LDB_SUCCESS;
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
15 | static int samldb_prim_group_trigger(struct samldb_ctx *ac)
{
int ret;
if (ac->req->operation == LDB_ADD) {
ret = samldb_prim_group_set(ac);
} else {
ret = samldb_prim_group_change(ac);
}
return ret;
}
| Bypass | 0 | static int samldb_prim_group_trigger(struct samldb_ctx *ac)
{
int ret;
if (ac->req->operation == LDB_ADD) {
ret = samldb_prim_group_set(ac);
} else {
ret = samldb_prim_group_change(ac);
}
return ret;
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
16 | static int samldb_rodc_add(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
uint32_t krbtgt_number, i_start, i;
int ret;
char *newpass;
struct ldb_val newpass_utf16;
/* find a unused msDC-SecondaryKrbTgtNumber */
i_start = generate_random() & 0xFFFF;
if (i_start == 0) {
i_start = 1;
}
for (i=i_start; i<=0xFFFF; i++) {
if (samldb_krbtgtnumber_available(ac, i)) {
krbtgt_number = i;
goto found;
}
}
for (i=1; i<i_start; i++) {
if (samldb_krbtgtnumber_available(ac, i)) {
krbtgt_number = i;
goto found;
}
}
ldb_asprintf_errstring(ldb,
"%08X: Unable to find available msDS-SecondaryKrbTgtNumber",
W_ERROR_V(WERR_NO_SYSTEM_RESOURCES));
return LDB_ERR_OTHER;
found:
ret = ldb_msg_add_empty(ac->msg, "msDS-SecondaryKrbTgtNumber",
LDB_FLAG_INTERNAL_DISABLE_VALIDATION, NULL);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
"msDS-SecondaryKrbTgtNumber", krbtgt_number);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
ret = ldb_msg_add_fmt(ac->msg, "sAMAccountName", "krbtgt_%u",
krbtgt_number);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
newpass = generate_random_password(ac->msg, 128, 255);
if (newpass == NULL) {
return ldb_operr(ldb);
}
if (!convert_string_talloc(ac,
CH_UNIX, CH_UTF16,
newpass, strlen(newpass),
(void *)&newpass_utf16.data,
&newpass_utf16.length)) {
ldb_asprintf_errstring(ldb,
"samldb_rodc_add: "
"failed to generate UTF16 password from random password");
return LDB_ERR_OPERATIONS_ERROR;
}
ret = ldb_msg_add_steal_value(ac->msg, "clearTextPassword", &newpass_utf16);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
return samldb_next_step(ac);
}
| Bypass | 0 | static int samldb_rodc_add(struct samldb_ctx *ac)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
uint32_t krbtgt_number, i_start, i;
int ret;
char *newpass;
struct ldb_val newpass_utf16;
/* find a unused msDC-SecondaryKrbTgtNumber */
i_start = generate_random() & 0xFFFF;
if (i_start == 0) {
i_start = 1;
}
for (i=i_start; i<=0xFFFF; i++) {
if (samldb_krbtgtnumber_available(ac, i)) {
krbtgt_number = i;
goto found;
}
}
for (i=1; i<i_start; i++) {
if (samldb_krbtgtnumber_available(ac, i)) {
krbtgt_number = i;
goto found;
}
}
ldb_asprintf_errstring(ldb,
"%08X: Unable to find available msDS-SecondaryKrbTgtNumber",
W_ERROR_V(WERR_NO_SYSTEM_RESOURCES));
return LDB_ERR_OTHER;
found:
ret = ldb_msg_add_empty(ac->msg, "msDS-SecondaryKrbTgtNumber",
LDB_FLAG_INTERNAL_DISABLE_VALIDATION, NULL);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
ret = samdb_msg_add_uint(ldb, ac->msg, ac->msg,
"msDS-SecondaryKrbTgtNumber", krbtgt_number);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
ret = ldb_msg_add_fmt(ac->msg, "sAMAccountName", "krbtgt_%u",
krbtgt_number);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
newpass = generate_random_password(ac->msg, 128, 255);
if (newpass == NULL) {
return ldb_operr(ldb);
}
if (!convert_string_talloc(ac,
CH_UNIX, CH_UTF16,
newpass, strlen(newpass),
(void *)&newpass_utf16.data,
&newpass_utf16.length)) {
ldb_asprintf_errstring(ldb,
"samldb_rodc_add: "
"failed to generate UTF16 password from random password");
return LDB_ERR_OPERATIONS_ERROR;
}
ret = ldb_msg_add_steal_value(ac->msg, "clearTextPassword", &newpass_utf16);
if (ret != LDB_SUCCESS) {
return ldb_operr(ldb);
}
return samldb_next_step(ac);
}
| @@ -1558,12 +1558,15 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
struct security_token *user_token;
struct security_descriptor *domain_sd;
struct ldb_dn *domain_dn = ldb_get_default_basedn(ldb_module_get_ctx(ac->module));
+ struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
const struct uac_to_guid {
uint32_t uac;
+ uint32_t priv_to_change_from;
const char *oid;
const char *guid;
enum sec_privilege privilege;
bool delete_is_privileged;
+ bool admin_required;
const char *error_string;
} map[] = {
{
@@ -1591,6 +1594,16 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
.guid = GUID_DRS_DS_INSTALL_REPLICA,
.error_string = "Adding the UF_PARTIAL_SECRETS_ACCOUNT bit in userAccountControl requires the DS-Install-Replica right that was not given on the Domain object"
},
+ {
+ .uac = UF_WORKSTATION_TRUST_ACCOUNT,
+ .priv_to_change_from = UF_NORMAL_ACCOUNT,
+ .error_string = "Swapping UF_NORMAL_ACCOUNT to UF_WORKSTATION_TRUST_ACCOUNT requires the user to be a member of the domain admins group"
+ },
+ {
+ .uac = UF_NORMAL_ACCOUNT,
+ .priv_to_change_from = UF_WORKSTATION_TRUST_ACCOUNT,
+ .error_string = "Swapping UF_WORKSTATION_TRUST_ACCOUNT to UF_NORMAL_ACCOUNT requires the user to be a member of the domain admins group"
+ },
{
.uac = UF_INTERDOMAIN_TRUST_ACCOUNT,
.oid = DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID,
@@ -1643,7 +1656,7 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
return ldb_module_operr(ac->module);
}
- ret = dsdb_get_sd_from_ldb_message(ldb_module_get_ctx(ac->module),
+ ret = dsdb_get_sd_from_ldb_message(ldb,
ac, res->msgs[0], &domain_sd);
if (ret != LDB_SUCCESS) {
@@ -1670,12 +1683,19 @@ static int samldb_check_user_account_control_acl(struct samldb_ctx *ac,
if (have_priv == false) {
ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
}
- } else {
+ } else if (map[i].priv_to_change_from & user_account_control_old) {
+ bool is_admin = security_token_has_builtin_administrators(user_token);
+ if (is_admin == false) {
+ ret = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
+ }
+ } else if (map[i].guid) {
ret = acl_check_extended_right(ac, domain_sd,
user_token,
map[i].guid,
SEC_ADS_CONTROL_ACCESS,
sid);
+ } else {
+ ret = LDB_SUCCESS;
}
if (ret != LDB_SUCCESS) {
break; | CWE-264 | null | null |
17 | acl_get_file_mode(const char *path_p)
{
struct stat st;
if (stat(path_p, &st) != 0)
return NULL;
return acl_from_mode(st.st_mode);
}
| null | 0 | acl_get_file_mode(const char *path_p)
{
struct stat st;
if (stat(path_p, &st) != 0)
return NULL;
return acl_from_mode(st.st_mode);
}
| @@ -1,3 +1,6 @@+* Make sure that getfacl -R only calls stat(2) on symlinks when it needs to.+ This fixes http://oss.sgi.com/bugzilla/show_bug.cgi?id=790 "getfacl follows+ symlinks, even without -L". * Stop quoting nonprintable characters in the getfacl output: what is printable or not depends on the locale settings, and getfacl often gets it wrong. We still need to quote a few special characters like newlines so that setfacldiff --git a/getfacl/getfacl.c b/getfacl/getfacl.c
index fc650e3..b3e6200 100644
--- a/getfacl/getfacl.c
+++ b/getfacl/getfacl.c@@ -70,7 +70,7 @@ struct option long_options[] = { const char *progname; const char *cmd_line_options; -int walk_flags = WALK_TREE_DEREFERENCE;+int walk_flags = WALK_TREE_DEREFERENCE_TOPLEVEL; int opt_print_acl; int opt_print_default_acl; int opt_strip_leading_slash = 1;@@ -642,7 +642,7 @@ int main(int argc, char *argv[]) case 'L': /* follow all symlinks */ if (posixly_correct) goto synopsis;- walk_flags |= WALK_TREE_LOGICAL;+ walk_flags |= WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE; walk_flags &= ~WALK_TREE_PHYSICAL; break; @@ -650,7 +650,8 @@ int main(int argc, char *argv[]) if (posixly_correct) goto synopsis; walk_flags |= WALK_TREE_PHYSICAL;- walk_flags &= ~WALK_TREE_LOGICAL;+ walk_flags &= ~(WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE |+ WALK_TREE_DEREFERENCE_TOPLEVEL); break; case 's': /* skip files with only base entries */ | CWE-264 | null | null |
18 | void acl_mask_perm_str(acl_t acl, char *str)
{
acl_entry_t entry;
str[0] = '\0';
if (acl_get_entry(acl, ACL_FIRST_ENTRY, &entry) != 1)
return;
for(;;) {
acl_tag_t tag;
acl_get_tag_type(entry, &tag);
if (tag == ACL_MASK) {
acl_perm_str(entry, str);
return;
}
if (acl_get_entry(acl, ACL_NEXT_ENTRY, &entry) != 1)
return;
}
}
| null | 0 | void acl_mask_perm_str(acl_t acl, char *str)
{
acl_entry_t entry;
str[0] = '\0';
if (acl_get_entry(acl, ACL_FIRST_ENTRY, &entry) != 1)
return;
for(;;) {
acl_tag_t tag;
acl_get_tag_type(entry, &tag);
if (tag == ACL_MASK) {
acl_perm_str(entry, str);
return;
}
if (acl_get_entry(acl, ACL_NEXT_ENTRY, &entry) != 1)
return;
}
}
| @@ -1,3 +1,6 @@+* Make sure that getfacl -R only calls stat(2) on symlinks when it needs to.+ This fixes http://oss.sgi.com/bugzilla/show_bug.cgi?id=790 "getfacl follows+ symlinks, even without -L". * Stop quoting nonprintable characters in the getfacl output: what is printable or not depends on the locale settings, and getfacl often gets it wrong. We still need to quote a few special characters like newlines so that setfacldiff --git a/getfacl/getfacl.c b/getfacl/getfacl.c
index fc650e3..b3e6200 100644
--- a/getfacl/getfacl.c
+++ b/getfacl/getfacl.c@@ -70,7 +70,7 @@ struct option long_options[] = { const char *progname; const char *cmd_line_options; -int walk_flags = WALK_TREE_DEREFERENCE;+int walk_flags = WALK_TREE_DEREFERENCE_TOPLEVEL; int opt_print_acl; int opt_print_default_acl; int opt_strip_leading_slash = 1;@@ -642,7 +642,7 @@ int main(int argc, char *argv[]) case 'L': /* follow all symlinks */ if (posixly_correct) goto synopsis;- walk_flags |= WALK_TREE_LOGICAL;+ walk_flags |= WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE; walk_flags &= ~WALK_TREE_PHYSICAL; break; @@ -650,7 +650,8 @@ int main(int argc, char *argv[]) if (posixly_correct) goto synopsis; walk_flags |= WALK_TREE_PHYSICAL;- walk_flags &= ~WALK_TREE_LOGICAL;+ walk_flags &= ~(WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE |+ WALK_TREE_DEREFERENCE_TOPLEVEL); break; case 's': /* skip files with only base entries */ | CWE-264 | null | null |
19 | void apply_mask(char *perm, const char *mask)
{
while (*perm) {
if (*mask == '-' && *perm >= 'a' && *perm <= 'z')
*perm = *perm - 'a' + 'A';
perm++;
if (*mask)
mask++;
}
}
| null | 0 | void apply_mask(char *perm, const char *mask)
{
while (*perm) {
if (*mask == '-' && *perm >= 'a' && *perm <= 'z')
*perm = *perm - 'a' + 'A';
perm++;
if (*mask)
mask++;
}
}
| @@ -1,3 +1,6 @@+* Make sure that getfacl -R only calls stat(2) on symlinks when it needs to.+ This fixes http://oss.sgi.com/bugzilla/show_bug.cgi?id=790 "getfacl follows+ symlinks, even without -L". * Stop quoting nonprintable characters in the getfacl output: what is printable or not depends on the locale settings, and getfacl often gets it wrong. We still need to quote a few special characters like newlines so that setfacldiff --git a/getfacl/getfacl.c b/getfacl/getfacl.c
index fc650e3..b3e6200 100644
--- a/getfacl/getfacl.c
+++ b/getfacl/getfacl.c@@ -70,7 +70,7 @@ struct option long_options[] = { const char *progname; const char *cmd_line_options; -int walk_flags = WALK_TREE_DEREFERENCE;+int walk_flags = WALK_TREE_DEREFERENCE_TOPLEVEL; int opt_print_acl; int opt_print_default_acl; int opt_strip_leading_slash = 1;@@ -642,7 +642,7 @@ int main(int argc, char *argv[]) case 'L': /* follow all symlinks */ if (posixly_correct) goto synopsis;- walk_flags |= WALK_TREE_LOGICAL;+ walk_flags |= WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE; walk_flags &= ~WALK_TREE_PHYSICAL; break; @@ -650,7 +650,8 @@ int main(int argc, char *argv[]) if (posixly_correct) goto synopsis; walk_flags |= WALK_TREE_PHYSICAL;- walk_flags &= ~WALK_TREE_LOGICAL;+ walk_flags &= ~(WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE |+ WALK_TREE_DEREFERENCE_TOPLEVEL); break; case 's': /* skip files with only base entries */ | CWE-264 | null | null |
20 | int do_show(FILE *stream, const char *path_p, const struct stat *st,
acl_t acl, acl_t dacl)
{
struct name_list *acl_names = get_list(st, acl),
*first_acl_name = acl_names;
struct name_list *dacl_names = get_list(st, dacl),
*first_dacl_name = dacl_names;
int acl_names_width = max_name_length(acl_names);
int dacl_names_width = max_name_length(dacl_names);
acl_entry_t acl_ent;
acl_entry_t dacl_ent;
char acl_mask[ACL_PERMS+1], dacl_mask[ACL_PERMS+1];
int ret;
names_width = 8;
if (acl_names_width > names_width)
names_width = acl_names_width;
if (dacl_names_width > names_width)
names_width = dacl_names_width;
acl_mask[0] = '\0';
if (acl) {
acl_mask_perm_str(acl, acl_mask);
ret = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_ent);
if (ret == 0)
acl = NULL;
if (ret < 0)
return ret;
}
dacl_mask[0] = '\0';
if (dacl) {
acl_mask_perm_str(dacl, dacl_mask);
ret = acl_get_entry(dacl, ACL_FIRST_ENTRY, &dacl_ent);
if (ret == 0)
dacl = NULL;
if (ret < 0)
return ret;
}
fprintf(stream, "# file: %s\n", xquote(path_p, "\n\r"));
while (acl_names != NULL || dacl_names != NULL) {
acl_tag_t acl_tag, dacl_tag;
if (acl)
acl_get_tag_type(acl_ent, &acl_tag);
if (dacl)
acl_get_tag_type(dacl_ent, &dacl_tag);
if (acl && (!dacl || acl_tag < dacl_tag)) {
show_line(stream, &acl_names, acl, &acl_ent, acl_mask,
NULL, NULL, NULL, NULL);
continue;
} else if (dacl && (!acl || dacl_tag < acl_tag)) {
show_line(stream, NULL, NULL, NULL, NULL,
&dacl_names, dacl, &dacl_ent, dacl_mask);
continue;
} else {
if (acl_tag == ACL_USER || acl_tag == ACL_GROUP) {
id_t *acl_id_p = NULL, *dacl_id_p = NULL;
if (acl_ent)
acl_id_p = acl_get_qualifier(acl_ent);
if (dacl_ent)
dacl_id_p = acl_get_qualifier(dacl_ent);
if (acl && (!dacl || *acl_id_p < *dacl_id_p)) {
show_line(stream, &acl_names, acl,
&acl_ent, acl_mask,
NULL, NULL, NULL, NULL);
continue;
} else if (dacl &&
(!acl || *dacl_id_p < *acl_id_p)) {
show_line(stream, NULL, NULL, NULL,
NULL, &dacl_names, dacl,
&dacl_ent, dacl_mask);
continue;
}
}
show_line(stream, &acl_names, acl, &acl_ent, acl_mask,
&dacl_names, dacl, &dacl_ent, dacl_mask);
}
}
free_list(first_acl_name);
free_list(first_dacl_name);
return 0;
}
| null | 0 | int do_show(FILE *stream, const char *path_p, const struct stat *st,
acl_t acl, acl_t dacl)
{
struct name_list *acl_names = get_list(st, acl),
*first_acl_name = acl_names;
struct name_list *dacl_names = get_list(st, dacl),
*first_dacl_name = dacl_names;
int acl_names_width = max_name_length(acl_names);
int dacl_names_width = max_name_length(dacl_names);
acl_entry_t acl_ent;
acl_entry_t dacl_ent;
char acl_mask[ACL_PERMS+1], dacl_mask[ACL_PERMS+1];
int ret;
names_width = 8;
if (acl_names_width > names_width)
names_width = acl_names_width;
if (dacl_names_width > names_width)
names_width = dacl_names_width;
acl_mask[0] = '\0';
if (acl) {
acl_mask_perm_str(acl, acl_mask);
ret = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_ent);
if (ret == 0)
acl = NULL;
if (ret < 0)
return ret;
}
dacl_mask[0] = '\0';
if (dacl) {
acl_mask_perm_str(dacl, dacl_mask);
ret = acl_get_entry(dacl, ACL_FIRST_ENTRY, &dacl_ent);
if (ret == 0)
dacl = NULL;
if (ret < 0)
return ret;
}
fprintf(stream, "# file: %s\n", xquote(path_p, "\n\r"));
while (acl_names != NULL || dacl_names != NULL) {
acl_tag_t acl_tag, dacl_tag;
if (acl)
acl_get_tag_type(acl_ent, &acl_tag);
if (dacl)
acl_get_tag_type(dacl_ent, &dacl_tag);
if (acl && (!dacl || acl_tag < dacl_tag)) {
show_line(stream, &acl_names, acl, &acl_ent, acl_mask,
NULL, NULL, NULL, NULL);
continue;
} else if (dacl && (!acl || dacl_tag < acl_tag)) {
show_line(stream, NULL, NULL, NULL, NULL,
&dacl_names, dacl, &dacl_ent, dacl_mask);
continue;
} else {
if (acl_tag == ACL_USER || acl_tag == ACL_GROUP) {
id_t *acl_id_p = NULL, *dacl_id_p = NULL;
if (acl_ent)
acl_id_p = acl_get_qualifier(acl_ent);
if (dacl_ent)
dacl_id_p = acl_get_qualifier(dacl_ent);
if (acl && (!dacl || *acl_id_p < *dacl_id_p)) {
show_line(stream, &acl_names, acl,
&acl_ent, acl_mask,
NULL, NULL, NULL, NULL);
continue;
} else if (dacl &&
(!acl || *dacl_id_p < *acl_id_p)) {
show_line(stream, NULL, NULL, NULL,
NULL, &dacl_names, dacl,
&dacl_ent, dacl_mask);
continue;
}
}
show_line(stream, &acl_names, acl, &acl_ent, acl_mask,
&dacl_names, dacl, &dacl_ent, dacl_mask);
}
}
free_list(first_acl_name);
free_list(first_dacl_name);
return 0;
}
| @@ -1,3 +1,6 @@+* Make sure that getfacl -R only calls stat(2) on symlinks when it needs to.+ This fixes http://oss.sgi.com/bugzilla/show_bug.cgi?id=790 "getfacl follows+ symlinks, even without -L". * Stop quoting nonprintable characters in the getfacl output: what is printable or not depends on the locale settings, and getfacl often gets it wrong. We still need to quote a few special characters like newlines so that setfacldiff --git a/getfacl/getfacl.c b/getfacl/getfacl.c
index fc650e3..b3e6200 100644
--- a/getfacl/getfacl.c
+++ b/getfacl/getfacl.c@@ -70,7 +70,7 @@ struct option long_options[] = { const char *progname; const char *cmd_line_options; -int walk_flags = WALK_TREE_DEREFERENCE;+int walk_flags = WALK_TREE_DEREFERENCE_TOPLEVEL; int opt_print_acl; int opt_print_default_acl; int opt_strip_leading_slash = 1;@@ -642,7 +642,7 @@ int main(int argc, char *argv[]) case 'L': /* follow all symlinks */ if (posixly_correct) goto synopsis;- walk_flags |= WALK_TREE_LOGICAL;+ walk_flags |= WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE; walk_flags &= ~WALK_TREE_PHYSICAL; break; @@ -650,7 +650,8 @@ int main(int argc, char *argv[]) if (posixly_correct) goto synopsis; walk_flags |= WALK_TREE_PHYSICAL;- walk_flags &= ~WALK_TREE_LOGICAL;+ walk_flags &= ~(WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE |+ WALK_TREE_DEREFERENCE_TOPLEVEL); break; case 's': /* skip files with only base entries */ | CWE-264 | null | null |
21 | void free_list(struct name_list *names)
{
struct name_list *next;
while (names) {
next = names->next;
free(names);
names = next;
}
}
| null | 0 | void free_list(struct name_list *names)
{
struct name_list *next;
while (names) {
next = names->next;
free(names);
names = next;
}
}
| @@ -1,3 +1,6 @@+* Make sure that getfacl -R only calls stat(2) on symlinks when it needs to.+ This fixes http://oss.sgi.com/bugzilla/show_bug.cgi?id=790 "getfacl follows+ symlinks, even without -L". * Stop quoting nonprintable characters in the getfacl output: what is printable or not depends on the locale settings, and getfacl often gets it wrong. We still need to quote a few special characters like newlines so that setfacldiff --git a/getfacl/getfacl.c b/getfacl/getfacl.c
index fc650e3..b3e6200 100644
--- a/getfacl/getfacl.c
+++ b/getfacl/getfacl.c@@ -70,7 +70,7 @@ struct option long_options[] = { const char *progname; const char *cmd_line_options; -int walk_flags = WALK_TREE_DEREFERENCE;+int walk_flags = WALK_TREE_DEREFERENCE_TOPLEVEL; int opt_print_acl; int opt_print_default_acl; int opt_strip_leading_slash = 1;@@ -642,7 +642,7 @@ int main(int argc, char *argv[]) case 'L': /* follow all symlinks */ if (posixly_correct) goto synopsis;- walk_flags |= WALK_TREE_LOGICAL;+ walk_flags |= WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE; walk_flags &= ~WALK_TREE_PHYSICAL; break; @@ -650,7 +650,8 @@ int main(int argc, char *argv[]) if (posixly_correct) goto synopsis; walk_flags |= WALK_TREE_PHYSICAL;- walk_flags &= ~WALK_TREE_LOGICAL;+ walk_flags &= ~(WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE |+ WALK_TREE_DEREFERENCE_TOPLEVEL); break; case 's': /* skip files with only base entries */ | CWE-264 | null | null |
22 | struct name_list *get_list(const struct stat *st, acl_t acl)
{
struct name_list *first = NULL, *last = NULL;
acl_entry_t ent;
int ret = 0;
if (acl != NULL)
ret = acl_get_entry(acl, ACL_FIRST_ENTRY, &ent);
if (ret != 1)
return NULL;
while (ret > 0) {
acl_tag_t e_type;
const id_t *id_p;
const char *name = "";
int len;
acl_get_tag_type(ent, &e_type);
switch(e_type) {
case ACL_USER_OBJ:
name = user_name(st->st_uid, opt_numeric);
break;
case ACL_USER:
id_p = acl_get_qualifier(ent);
if (id_p != NULL)
name = user_name(*id_p, opt_numeric);
break;
case ACL_GROUP_OBJ:
name = group_name(st->st_gid, opt_numeric);
break;
case ACL_GROUP:
id_p = acl_get_qualifier(ent);
if (id_p != NULL)
name = group_name(*id_p, opt_numeric);
break;
}
name = xquote(name, "\t\n\r");
len = strlen(name);
if (last == NULL) {
first = last = (struct name_list *)
malloc(sizeof(struct name_list) + len + 1);
} else {
last->next = (struct name_list *)
malloc(sizeof(struct name_list) + len + 1);
last = last->next;
}
if (last == NULL) {
free_list(first);
return NULL;
}
last->next = NULL;
strcpy(last->name, name);
ret = acl_get_entry(acl, ACL_NEXT_ENTRY, &ent);
}
return first;
}
| null | 0 | struct name_list *get_list(const struct stat *st, acl_t acl)
{
struct name_list *first = NULL, *last = NULL;
acl_entry_t ent;
int ret = 0;
if (acl != NULL)
ret = acl_get_entry(acl, ACL_FIRST_ENTRY, &ent);
if (ret != 1)
return NULL;
while (ret > 0) {
acl_tag_t e_type;
const id_t *id_p;
const char *name = "";
int len;
acl_get_tag_type(ent, &e_type);
switch(e_type) {
case ACL_USER_OBJ:
name = user_name(st->st_uid, opt_numeric);
break;
case ACL_USER:
id_p = acl_get_qualifier(ent);
if (id_p != NULL)
name = user_name(*id_p, opt_numeric);
break;
case ACL_GROUP_OBJ:
name = group_name(st->st_gid, opt_numeric);
break;
case ACL_GROUP:
id_p = acl_get_qualifier(ent);
if (id_p != NULL)
name = group_name(*id_p, opt_numeric);
break;
}
name = xquote(name, "\t\n\r");
len = strlen(name);
if (last == NULL) {
first = last = (struct name_list *)
malloc(sizeof(struct name_list) + len + 1);
} else {
last->next = (struct name_list *)
malloc(sizeof(struct name_list) + len + 1);
last = last->next;
}
if (last == NULL) {
free_list(first);
return NULL;
}
last->next = NULL;
strcpy(last->name, name);
ret = acl_get_entry(acl, ACL_NEXT_ENTRY, &ent);
}
return first;
}
| @@ -1,3 +1,6 @@+* Make sure that getfacl -R only calls stat(2) on symlinks when it needs to.+ This fixes http://oss.sgi.com/bugzilla/show_bug.cgi?id=790 "getfacl follows+ symlinks, even without -L". * Stop quoting nonprintable characters in the getfacl output: what is printable or not depends on the locale settings, and getfacl often gets it wrong. We still need to quote a few special characters like newlines so that setfacldiff --git a/getfacl/getfacl.c b/getfacl/getfacl.c
index fc650e3..b3e6200 100644
--- a/getfacl/getfacl.c
+++ b/getfacl/getfacl.c@@ -70,7 +70,7 @@ struct option long_options[] = { const char *progname; const char *cmd_line_options; -int walk_flags = WALK_TREE_DEREFERENCE;+int walk_flags = WALK_TREE_DEREFERENCE_TOPLEVEL; int opt_print_acl; int opt_print_default_acl; int opt_strip_leading_slash = 1;@@ -642,7 +642,7 @@ int main(int argc, char *argv[]) case 'L': /* follow all symlinks */ if (posixly_correct) goto synopsis;- walk_flags |= WALK_TREE_LOGICAL;+ walk_flags |= WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE; walk_flags &= ~WALK_TREE_PHYSICAL; break; @@ -650,7 +650,8 @@ int main(int argc, char *argv[]) if (posixly_correct) goto synopsis; walk_flags |= WALK_TREE_PHYSICAL;- walk_flags &= ~WALK_TREE_LOGICAL;+ walk_flags &= ~(WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE |+ WALK_TREE_DEREFERENCE_TOPLEVEL); break; case 's': /* skip files with only base entries */ | CWE-264 | null | null |
23 | void help(void)
{
printf(_("%s %s -- get file access control lists\n"),
progname, VERSION);
printf(_("Usage: %s [-%s] file ...\n"),
progname, cmd_line_options);
#if !POSIXLY_CORRECT
if (posixly_correct) {
#endif
printf(_(
" -d, --default display the default access control list\n"));
#if !POSIXLY_CORRECT
} else {
printf(_(
" -a, --access display the file access control list only\n"
" -d, --default display the default access control list only\n"
" -c, --omit-header do not display the comment header\n"
" -e, --all-effective print all effective rights\n"
" -E, --no-effective print no effective rights\n"
" -s, --skip-base skip files that only have the base entries\n"
" -R, --recursive recurse into subdirectories\n"
" -L, --logical logical walk, follow symbolic links\n"
" -P, --physical physical walk, do not follow symbolic links\n"
" -t, --tabular use tabular output format\n"
" -n, --numeric print numeric user/group identifiers\n"
" -p, --absolute-names don't strip leading '/' in pathnames\n"));
}
#endif
printf(_(
" -v, --version print version and exit\n"
" -h, --help this help text\n"));
}
| null | 0 | void help(void)
{
printf(_("%s %s -- get file access control lists\n"),
progname, VERSION);
printf(_("Usage: %s [-%s] file ...\n"),
progname, cmd_line_options);
#if !POSIXLY_CORRECT
if (posixly_correct) {
#endif
printf(_(
" -d, --default display the default access control list\n"));
#if !POSIXLY_CORRECT
} else {
printf(_(
" -a, --access display the file access control list only\n"
" -d, --default display the default access control list only\n"
" -c, --omit-header do not display the comment header\n"
" -e, --all-effective print all effective rights\n"
" -E, --no-effective print no effective rights\n"
" -s, --skip-base skip files that only have the base entries\n"
" -R, --recursive recurse into subdirectories\n"
" -L, --logical logical walk, follow symbolic links\n"
" -P, --physical physical walk, do not follow symbolic links\n"
" -t, --tabular use tabular output format\n"
" -n, --numeric print numeric user/group identifiers\n"
" -p, --absolute-names don't strip leading '/' in pathnames\n"));
}
#endif
printf(_(
" -v, --version print version and exit\n"
" -h, --help this help text\n"));
}
| @@ -1,3 +1,6 @@+* Make sure that getfacl -R only calls stat(2) on symlinks when it needs to.+ This fixes http://oss.sgi.com/bugzilla/show_bug.cgi?id=790 "getfacl follows+ symlinks, even without -L". * Stop quoting nonprintable characters in the getfacl output: what is printable or not depends on the locale settings, and getfacl often gets it wrong. We still need to quote a few special characters like newlines so that setfacldiff --git a/getfacl/getfacl.c b/getfacl/getfacl.c
index fc650e3..b3e6200 100644
--- a/getfacl/getfacl.c
+++ b/getfacl/getfacl.c@@ -70,7 +70,7 @@ struct option long_options[] = { const char *progname; const char *cmd_line_options; -int walk_flags = WALK_TREE_DEREFERENCE;+int walk_flags = WALK_TREE_DEREFERENCE_TOPLEVEL; int opt_print_acl; int opt_print_default_acl; int opt_strip_leading_slash = 1;@@ -642,7 +642,7 @@ int main(int argc, char *argv[]) case 'L': /* follow all symlinks */ if (posixly_correct) goto synopsis;- walk_flags |= WALK_TREE_LOGICAL;+ walk_flags |= WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE; walk_flags &= ~WALK_TREE_PHYSICAL; break; @@ -650,7 +650,8 @@ int main(int argc, char *argv[]) if (posixly_correct) goto synopsis; walk_flags |= WALK_TREE_PHYSICAL;- walk_flags &= ~WALK_TREE_LOGICAL;+ walk_flags &= ~(WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE |+ WALK_TREE_DEREFERENCE_TOPLEVEL); break; case 's': /* skip files with only base entries */ | CWE-264 | null | null |
24 | int main(int argc, char *argv[])
{
int opt;
char *line;
progname = basename(argv[0]);
#if POSIXLY_CORRECT
cmd_line_options = POSIXLY_CMD_LINE_OPTIONS;
#else
if (getenv(POSIXLY_CORRECT_STR))
posixly_correct = 1;
if (!posixly_correct)
cmd_line_options = CMD_LINE_OPTIONS;
else
cmd_line_options = POSIXLY_CMD_LINE_OPTIONS;
#endif
setlocale(LC_CTYPE, "");
setlocale(LC_MESSAGES, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
/* Align `#effective:' comments to column 40 for tty's */
if (!posixly_correct && isatty(fileno(stdout)))
print_options |= TEXT_SMART_INDENT;
while ((opt = getopt_long(argc, argv, cmd_line_options,
long_options, NULL)) != -1) {
switch (opt) {
case 'a': /* acl only */
if (posixly_correct)
goto synopsis;
opt_print_acl = 1;
break;
case 'd': /* default acl only */
opt_print_default_acl = 1;
break;
case 'c': /* no comments */
if (posixly_correct)
goto synopsis;
opt_comments = 0;
break;
case 'e': /* all #effective comments */
if (posixly_correct)
goto synopsis;
print_options |= TEXT_ALL_EFFECTIVE;
break;
case 'E': /* no #effective comments */
if (posixly_correct)
goto synopsis;
print_options &= ~(TEXT_SOME_EFFECTIVE |
TEXT_ALL_EFFECTIVE);
break;
case 'R': /* recursive */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_RECURSIVE;
break;
case 'L': /* follow all symlinks */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_LOGICAL;
walk_flags &= ~WALK_TREE_PHYSICAL;
break;
case 'P': /* skip all symlinks */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_PHYSICAL;
walk_flags &= ~WALK_TREE_LOGICAL;
break;
case 's': /* skip files with only base entries */
if (posixly_correct)
goto synopsis;
opt_skip_base = 1;
break;
case 'p':
if (posixly_correct)
goto synopsis;
opt_strip_leading_slash = 0;
break;
case 't':
if (posixly_correct)
goto synopsis;
opt_tabular = 1;
break;
case 'n': /* numeric */
opt_numeric = 1;
print_options |= TEXT_NUMERIC_IDS;
break;
case 'v': /* print version */
printf("%s " VERSION "\n", progname);
return 0;
case 'h': /* help */
help();
return 0;
case ':': /* option missing */
case '?': /* unknown option */
default:
goto synopsis;
}
}
if (!(opt_print_acl || opt_print_default_acl)) {
opt_print_acl = 1;
if (!posixly_correct)
opt_print_default_acl = 1;
}
if ((optind == argc) && !posixly_correct)
goto synopsis;
do {
if (optind == argc ||
strcmp(argv[optind], "-") == 0) {
while ((line = next_line(stdin)) != NULL) {
if (*line == '\0')
continue;
had_errors += walk_tree(line, walk_flags, 0,
do_print, NULL);
}
if (!feof(stdin)) {
fprintf(stderr, _("%s: Standard input: %s\n"),
progname, strerror(errno));
had_errors++;
}
} else
had_errors += walk_tree(argv[optind], walk_flags, 0,
do_print, NULL);
optind++;
} while (optind < argc);
return had_errors ? 1 : 0;
synopsis:
fprintf(stderr, _("Usage: %s [-%s] file ...\n"),
progname, cmd_line_options);
fprintf(stderr, _("Try `%s --help' for more information.\n"),
progname);
return 2;
}
| null | 0 | int main(int argc, char *argv[])
{
int opt;
char *line;
progname = basename(argv[0]);
#if POSIXLY_CORRECT
cmd_line_options = POSIXLY_CMD_LINE_OPTIONS;
#else
if (getenv(POSIXLY_CORRECT_STR))
posixly_correct = 1;
if (!posixly_correct)
cmd_line_options = CMD_LINE_OPTIONS;
else
cmd_line_options = POSIXLY_CMD_LINE_OPTIONS;
#endif
setlocale(LC_CTYPE, "");
setlocale(LC_MESSAGES, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
/* Align `#effective:' comments to column 40 for tty's */
if (!posixly_correct && isatty(fileno(stdout)))
print_options |= TEXT_SMART_INDENT;
while ((opt = getopt_long(argc, argv, cmd_line_options,
long_options, NULL)) != -1) {
switch (opt) {
case 'a': /* acl only */
if (posixly_correct)
goto synopsis;
opt_print_acl = 1;
break;
case 'd': /* default acl only */
opt_print_default_acl = 1;
break;
case 'c': /* no comments */
if (posixly_correct)
goto synopsis;
opt_comments = 0;
break;
case 'e': /* all #effective comments */
if (posixly_correct)
goto synopsis;
print_options |= TEXT_ALL_EFFECTIVE;
break;
case 'E': /* no #effective comments */
if (posixly_correct)
goto synopsis;
print_options &= ~(TEXT_SOME_EFFECTIVE |
TEXT_ALL_EFFECTIVE);
break;
case 'R': /* recursive */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_RECURSIVE;
break;
case 'L': /* follow all symlinks */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_LOGICAL;
walk_flags &= ~WALK_TREE_PHYSICAL;
break;
case 'P': /* skip all symlinks */
if (posixly_correct)
goto synopsis;
walk_flags |= WALK_TREE_PHYSICAL;
walk_flags &= ~WALK_TREE_LOGICAL;
break;
case 's': /* skip files with only base entries */
if (posixly_correct)
goto synopsis;
opt_skip_base = 1;
break;
case 'p':
if (posixly_correct)
goto synopsis;
opt_strip_leading_slash = 0;
break;
case 't':
if (posixly_correct)
goto synopsis;
opt_tabular = 1;
break;
case 'n': /* numeric */
opt_numeric = 1;
print_options |= TEXT_NUMERIC_IDS;
break;
case 'v': /* print version */
printf("%s " VERSION "\n", progname);
return 0;
case 'h': /* help */
help();
return 0;
case ':': /* option missing */
case '?': /* unknown option */
default:
goto synopsis;
}
}
if (!(opt_print_acl || opt_print_default_acl)) {
opt_print_acl = 1;
if (!posixly_correct)
opt_print_default_acl = 1;
}
if ((optind == argc) && !posixly_correct)
goto synopsis;
do {
if (optind == argc ||
strcmp(argv[optind], "-") == 0) {
while ((line = next_line(stdin)) != NULL) {
if (*line == '\0')
continue;
had_errors += walk_tree(line, walk_flags, 0,
do_print, NULL);
}
if (!feof(stdin)) {
fprintf(stderr, _("%s: Standard input: %s\n"),
progname, strerror(errno));
had_errors++;
}
} else
had_errors += walk_tree(argv[optind], walk_flags, 0,
do_print, NULL);
optind++;
} while (optind < argc);
return had_errors ? 1 : 0;
synopsis:
fprintf(stderr, _("Usage: %s [-%s] file ...\n"),
progname, cmd_line_options);
fprintf(stderr, _("Try `%s --help' for more information.\n"),
progname);
return 2;
}
| @@ -1,3 +1,6 @@+* Make sure that getfacl -R only calls stat(2) on symlinks when it needs to.+ This fixes http://oss.sgi.com/bugzilla/show_bug.cgi?id=790 "getfacl follows+ symlinks, even without -L". * Stop quoting nonprintable characters in the getfacl output: what is printable or not depends on the locale settings, and getfacl often gets it wrong. We still need to quote a few special characters like newlines so that setfacldiff --git a/getfacl/getfacl.c b/getfacl/getfacl.c
index fc650e3..b3e6200 100644
--- a/getfacl/getfacl.c
+++ b/getfacl/getfacl.c@@ -70,7 +70,7 @@ struct option long_options[] = { const char *progname; const char *cmd_line_options; -int walk_flags = WALK_TREE_DEREFERENCE;+int walk_flags = WALK_TREE_DEREFERENCE_TOPLEVEL; int opt_print_acl; int opt_print_default_acl; int opt_strip_leading_slash = 1;@@ -642,7 +642,7 @@ int main(int argc, char *argv[]) case 'L': /* follow all symlinks */ if (posixly_correct) goto synopsis;- walk_flags |= WALK_TREE_LOGICAL;+ walk_flags |= WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE; walk_flags &= ~WALK_TREE_PHYSICAL; break; @@ -650,7 +650,8 @@ int main(int argc, char *argv[]) if (posixly_correct) goto synopsis; walk_flags |= WALK_TREE_PHYSICAL;- walk_flags &= ~WALK_TREE_LOGICAL;+ walk_flags &= ~(WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE |+ WALK_TREE_DEREFERENCE_TOPLEVEL); break; case 's': /* skip files with only base entries */ | CWE-264 | null | null |
25 | int show_line(FILE *stream, struct name_list **acl_names, acl_t acl,
acl_entry_t *acl_ent, const char *acl_mask,
struct name_list **dacl_names, acl_t dacl,
acl_entry_t *dacl_ent, const char *dacl_mask)
{
acl_tag_t tag_type;
const char *tag, *name;
char acl_perm[ACL_PERMS+1], dacl_perm[ACL_PERMS+1];
if (acl) {
acl_get_tag_type(*acl_ent, &tag_type);
name = (*acl_names)->name;
} else {
acl_get_tag_type(*dacl_ent, &tag_type);
name = (*dacl_names)->name;
}
switch(tag_type) {
case ACL_USER_OBJ:
tag = "USER";
break;
case ACL_USER:
tag = "user";
break;
case ACL_GROUP_OBJ:
tag = "GROUP";
break;
case ACL_GROUP:
tag = "group";
break;
case ACL_MASK:
tag = "mask";
break;
case ACL_OTHER:
tag = "other";
break;
default:
return -1;
}
memset(acl_perm, ' ', ACL_PERMS);
acl_perm[ACL_PERMS] = '\0';
if (acl_ent) {
acl_perm_str(*acl_ent, acl_perm);
if (tag_type != ACL_USER_OBJ && tag_type != ACL_OTHER &&
tag_type != ACL_MASK)
apply_mask(acl_perm, acl_mask);
}
memset(dacl_perm, ' ', ACL_PERMS);
dacl_perm[ACL_PERMS] = '\0';
if (dacl_ent) {
acl_perm_str(*dacl_ent, dacl_perm);
if (tag_type != ACL_USER_OBJ && tag_type != ACL_OTHER &&
tag_type != ACL_MASK)
apply_mask(dacl_perm, dacl_mask);
}
fprintf(stream, "%-5s %*s %*s %*s\n",
tag, -names_width, name,
-(int)ACL_PERMS, acl_perm,
-(int)ACL_PERMS, dacl_perm);
if (acl_names) {
acl_get_entry(acl, ACL_NEXT_ENTRY, acl_ent);
(*acl_names) = (*acl_names)->next;
}
if (dacl_names) {
acl_get_entry(dacl, ACL_NEXT_ENTRY, dacl_ent);
(*dacl_names) = (*dacl_names)->next;
}
return 0;
}
| null | 0 | int show_line(FILE *stream, struct name_list **acl_names, acl_t acl,
acl_entry_t *acl_ent, const char *acl_mask,
struct name_list **dacl_names, acl_t dacl,
acl_entry_t *dacl_ent, const char *dacl_mask)
{
acl_tag_t tag_type;
const char *tag, *name;
char acl_perm[ACL_PERMS+1], dacl_perm[ACL_PERMS+1];
if (acl) {
acl_get_tag_type(*acl_ent, &tag_type);
name = (*acl_names)->name;
} else {
acl_get_tag_type(*dacl_ent, &tag_type);
name = (*dacl_names)->name;
}
switch(tag_type) {
case ACL_USER_OBJ:
tag = "USER";
break;
case ACL_USER:
tag = "user";
break;
case ACL_GROUP_OBJ:
tag = "GROUP";
break;
case ACL_GROUP:
tag = "group";
break;
case ACL_MASK:
tag = "mask";
break;
case ACL_OTHER:
tag = "other";
break;
default:
return -1;
}
memset(acl_perm, ' ', ACL_PERMS);
acl_perm[ACL_PERMS] = '\0';
if (acl_ent) {
acl_perm_str(*acl_ent, acl_perm);
if (tag_type != ACL_USER_OBJ && tag_type != ACL_OTHER &&
tag_type != ACL_MASK)
apply_mask(acl_perm, acl_mask);
}
memset(dacl_perm, ' ', ACL_PERMS);
dacl_perm[ACL_PERMS] = '\0';
if (dacl_ent) {
acl_perm_str(*dacl_ent, dacl_perm);
if (tag_type != ACL_USER_OBJ && tag_type != ACL_OTHER &&
tag_type != ACL_MASK)
apply_mask(dacl_perm, dacl_mask);
}
fprintf(stream, "%-5s %*s %*s %*s\n",
tag, -names_width, name,
-(int)ACL_PERMS, acl_perm,
-(int)ACL_PERMS, dacl_perm);
if (acl_names) {
acl_get_entry(acl, ACL_NEXT_ENTRY, acl_ent);
(*acl_names) = (*acl_names)->next;
}
if (dacl_names) {
acl_get_entry(dacl, ACL_NEXT_ENTRY, dacl_ent);
(*dacl_names) = (*dacl_names)->next;
}
return 0;
}
| @@ -1,3 +1,6 @@+* Make sure that getfacl -R only calls stat(2) on symlinks when it needs to.+ This fixes http://oss.sgi.com/bugzilla/show_bug.cgi?id=790 "getfacl follows+ symlinks, even without -L". * Stop quoting nonprintable characters in the getfacl output: what is printable or not depends on the locale settings, and getfacl often gets it wrong. We still need to quote a few special characters like newlines so that setfacldiff --git a/getfacl/getfacl.c b/getfacl/getfacl.c
index fc650e3..b3e6200 100644
--- a/getfacl/getfacl.c
+++ b/getfacl/getfacl.c@@ -70,7 +70,7 @@ struct option long_options[] = { const char *progname; const char *cmd_line_options; -int walk_flags = WALK_TREE_DEREFERENCE;+int walk_flags = WALK_TREE_DEREFERENCE_TOPLEVEL; int opt_print_acl; int opt_print_default_acl; int opt_strip_leading_slash = 1;@@ -642,7 +642,7 @@ int main(int argc, char *argv[]) case 'L': /* follow all symlinks */ if (posixly_correct) goto synopsis;- walk_flags |= WALK_TREE_LOGICAL;+ walk_flags |= WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE; walk_flags &= ~WALK_TREE_PHYSICAL; break; @@ -650,7 +650,8 @@ int main(int argc, char *argv[]) if (posixly_correct) goto synopsis; walk_flags |= WALK_TREE_PHYSICAL;- walk_flags &= ~WALK_TREE_LOGICAL;+ walk_flags &= ~(WALK_TREE_LOGICAL | WALK_TREE_DEREFERENCE |+ WALK_TREE_DEREFERENCE_TOPLEVEL); break; case 's': /* skip files with only base entries */ | CWE-264 | null | null |
26 | static PHP_FUNCTION(preg_match_all)
{
php_do_pcre_match(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
| DoS Overflow +Info | 0 | static PHP_FUNCTION(preg_match_all)
{
php_do_pcre_match(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
27 | static PHP_FUNCTION(preg_replace)
{
preg_replace_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
}
| DoS Overflow +Info | 0 | static PHP_FUNCTION(preg_replace)
{
preg_replace_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 0);
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
28 | static PHP_FUNCTION(preg_replace_callback)
{
preg_replace_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
}
| DoS Overflow +Info | 0 | static PHP_FUNCTION(preg_replace_callback)
{
preg_replace_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1, 0);
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
29 | static PHP_FUNCTION(preg_filter)
{
preg_replace_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
}
| DoS Overflow +Info | 0 | static PHP_FUNCTION(preg_filter)
{
preg_replace_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0, 1);
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
30 | static PHP_FUNCTION(preg_split)
{
char *regex; /* Regular expression */
char *subject; /* String to match against */
int regex_len;
int subject_len;
long limit_val = -1;/* Integer value of limit */
long flags = 0; /* Match control flags */
pcre_cache_entry *pce; /* Compiled regular expression */
/* Get function parameters and do error checking */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll", ®ex, ®ex_len,
&subject, &subject_len, &limit_val, &flags) == FAILURE) {
RETURN_FALSE;
}
/* Compile regex or get it from cache. */
if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
php_pcre_split_impl(pce, subject, subject_len, return_value, limit_val, flags TSRMLS_CC);
}
| DoS Overflow +Info | 0 | static PHP_FUNCTION(preg_split)
{
char *regex; /* Regular expression */
char *subject; /* String to match against */
int regex_len;
int subject_len;
long limit_val = -1;/* Integer value of limit */
long flags = 0; /* Match control flags */
pcre_cache_entry *pce; /* Compiled regular expression */
/* Get function parameters and do error checking */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll", ®ex, ®ex_len,
&subject, &subject_len, &limit_val, &flags) == FAILURE) {
RETURN_FALSE;
}
/* Compile regex or get it from cache. */
if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
php_pcre_split_impl(pce, subject, subject_len, return_value, limit_val, flags TSRMLS_CC);
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
31 | static PHP_FUNCTION(preg_quote)
{
int in_str_len;
char *in_str; /* Input string argument */
char *in_str_end; /* End of the input string */
int delim_len = 0;
char *delim = NULL; /* Additional delimiter argument */
char *out_str, /* Output string with quoted characters */
*p, /* Iterator for input string */
*q, /* Iterator for output string */
delim_char=0, /* Delimiter character to be quoted */
c; /* Current character */
zend_bool quote_delim = 0; /* Whether to quote additional delim char */
/* Get the arguments and check for errors */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &in_str, &in_str_len,
&delim, &delim_len) == FAILURE) {
return;
}
in_str_end = in_str + in_str_len;
/* Nothing to do if we got an empty string */
if (in_str == in_str_end) {
RETURN_EMPTY_STRING();
}
if (delim && *delim) {
delim_char = delim[0];
quote_delim = 1;
}
/* Allocate enough memory so that even if each character
is quoted, we won't run out of room */
out_str = safe_emalloc(4, in_str_len, 1);
/* Go through the string and quote necessary characters */
for(p = in_str, q = out_str; p != in_str_end; p++) {
c = *p;
switch(c) {
case '.':
case '\\':
case '+':
case '*':
case '?':
case '[':
case '^':
case ']':
case '$':
case '(':
case ')':
case '{':
case '}':
case '=':
case '!':
case '>':
case '<':
case '|':
case ':':
case '-':
*q++ = '\\';
*q++ = c;
break;
case '\0':
*q++ = '\\';
*q++ = '0';
*q++ = '0';
*q++ = '0';
break;
default:
if (quote_delim && c == delim_char)
*q++ = '\\';
*q++ = c;
break;
}
}
*q = '\0';
/* Reallocate string and return it */
RETVAL_STRINGL(erealloc(out_str, q - out_str + 1), q - out_str, 0);
}
| DoS Overflow +Info | 0 | static PHP_FUNCTION(preg_quote)
{
int in_str_len;
char *in_str; /* Input string argument */
char *in_str_end; /* End of the input string */
int delim_len = 0;
char *delim = NULL; /* Additional delimiter argument */
char *out_str, /* Output string with quoted characters */
*p, /* Iterator for input string */
*q, /* Iterator for output string */
delim_char=0, /* Delimiter character to be quoted */
c; /* Current character */
zend_bool quote_delim = 0; /* Whether to quote additional delim char */
/* Get the arguments and check for errors */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &in_str, &in_str_len,
&delim, &delim_len) == FAILURE) {
return;
}
in_str_end = in_str + in_str_len;
/* Nothing to do if we got an empty string */
if (in_str == in_str_end) {
RETURN_EMPTY_STRING();
}
if (delim && *delim) {
delim_char = delim[0];
quote_delim = 1;
}
/* Allocate enough memory so that even if each character
is quoted, we won't run out of room */
out_str = safe_emalloc(4, in_str_len, 1);
/* Go through the string and quote necessary characters */
for(p = in_str, q = out_str; p != in_str_end; p++) {
c = *p;
switch(c) {
case '.':
case '\\':
case '+':
case '*':
case '?':
case '[':
case '^':
case ']':
case '$':
case '(':
case ')':
case '{':
case '}':
case '=':
case '!':
case '>':
case '<':
case '|':
case ':':
case '-':
*q++ = '\\';
*q++ = c;
break;
case '\0':
*q++ = '\\';
*q++ = '0';
*q++ = '0';
*q++ = '0';
break;
default:
if (quote_delim && c == delim_char)
*q++ = '\\';
*q++ = c;
break;
}
}
*q = '\0';
/* Reallocate string and return it */
RETVAL_STRINGL(erealloc(out_str, q - out_str + 1), q - out_str, 0);
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
32 | static PHP_FUNCTION(preg_grep)
{
char *regex; /* Regular expression */
int regex_len;
zval *input; /* Input array */
long flags = 0; /* Match control flags */
pcre_cache_entry *pce; /* Compiled regular expression */
/* Get arguments and do error checking */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|l", ®ex, ®ex_len,
&input, &flags) == FAILURE) {
return;
}
/* Compile regex or get it from cache. */
if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
php_pcre_grep_impl(pce, input, return_value, flags TSRMLS_CC);
}
| DoS Overflow +Info | 0 | static PHP_FUNCTION(preg_grep)
{
char *regex; /* Regular expression */
int regex_len;
zval *input; /* Input array */
long flags = 0; /* Match control flags */
pcre_cache_entry *pce; /* Compiled regular expression */
/* Get arguments and do error checking */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|l", ®ex, ®ex_len,
&input, &flags) == FAILURE) {
return;
}
/* Compile regex or get it from cache. */
if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
php_pcre_grep_impl(pce, input, return_value, flags TSRMLS_CC);
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
33 | static PHP_GINIT_FUNCTION(pcre) /* {{{ */
{
zend_hash_init(&pcre_globals->pcre_cache, 0, NULL, php_free_pcre_cache, 1);
pcre_globals->backtrack_limit = 0;
pcre_globals->recursion_limit = 0;
pcre_globals->error_code = PHP_PCRE_NO_ERROR;
}
/* }}} */
| DoS Overflow +Info | 0 | static PHP_GINIT_FUNCTION(pcre) /* {{{ */
{
zend_hash_init(&pcre_globals->pcre_cache, 0, NULL, php_free_pcre_cache, 1);
pcre_globals->backtrack_limit = 0;
pcre_globals->recursion_limit = 0;
pcre_globals->error_code = PHP_PCRE_NO_ERROR;
}
/* }}} */
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
34 | static PHP_GSHUTDOWN_FUNCTION(pcre) /* {{{ */
{
zend_hash_destroy(&pcre_globals->pcre_cache);
}
/* }}} */
| DoS Overflow +Info | 0 | static PHP_GSHUTDOWN_FUNCTION(pcre) /* {{{ */
{
zend_hash_destroy(&pcre_globals->pcre_cache);
}
/* }}} */
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
35 | static PHP_MINFO_FUNCTION(pcre)
{
php_info_print_table_start();
php_info_print_table_row(2, "PCRE (Perl Compatible Regular Expressions) Support", "enabled" );
php_info_print_table_row(2, "PCRE Library Version", pcre_version() );
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
| DoS Overflow +Info | 0 | static PHP_MINFO_FUNCTION(pcre)
{
php_info_print_table_start();
php_info_print_table_row(2, "PCRE (Perl Compatible Regular Expressions) Support", "enabled" );
php_info_print_table_row(2, "PCRE Library Version", pcre_version() );
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
36 | static PHP_MINIT_FUNCTION(pcre)
{
REGISTER_INI_ENTRIES();
REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_OFFSET_ERROR", PHP_PCRE_BAD_UTF8_OFFSET_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("PCRE_VERSION", (char *)pcre_version(), CONST_CS | CONST_PERSISTENT);
return SUCCESS;
}
| DoS Overflow +Info | 0 | static PHP_MINIT_FUNCTION(pcre)
{
REGISTER_INI_ENTRIES();
REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_OFFSET_ERROR", PHP_PCRE_BAD_UTF8_OFFSET_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("PCRE_VERSION", (char *)pcre_version(), CONST_CS | CONST_PERSISTENT);
return SUCCESS;
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
37 | static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_DC)
{
pcre_extra *extra = pce->extra;
int name_cnt = 0, name_size, ni = 0;
int rc;
char *name_table;
unsigned short name_idx;
char **subpat_names = (char **)ecalloc(num_subpats, sizeof(char *));
rc = pcre_fullinfo(pce->re, extra, PCRE_INFO_NAMECOUNT, &name_cnt);
if (rc < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
efree(subpat_names);
return NULL;
}
if (name_cnt > 0) {
int rc1, rc2;
rc1 = pcre_fullinfo(pce->re, extra, PCRE_INFO_NAMETABLE, &name_table);
rc2 = pcre_fullinfo(pce->re, extra, PCRE_INFO_NAMEENTRYSIZE, &name_size);
rc = rc2 ? rc2 : rc1;
if (rc < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
efree(subpat_names);
return NULL;
}
while (ni++ < name_cnt) {
name_idx = 0xff * (unsigned char)name_table[0] + (unsigned char)name_table[1];
subpat_names[name_idx] = name_table + 2;
if (is_numeric_string(subpat_names[name_idx], strlen(subpat_names[name_idx]), NULL, NULL, 0) > 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Numeric named subpatterns are not allowed");
efree(subpat_names);
return NULL;
}
name_table += name_size;
}
}
return subpat_names;
}
| DoS Overflow +Info | 0 | static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_DC)
{
pcre_extra *extra = pce->extra;
int name_cnt = 0, name_size, ni = 0;
int rc;
char *name_table;
unsigned short name_idx;
char **subpat_names = (char **)ecalloc(num_subpats, sizeof(char *));
rc = pcre_fullinfo(pce->re, extra, PCRE_INFO_NAMECOUNT, &name_cnt);
if (rc < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
efree(subpat_names);
return NULL;
}
if (name_cnt > 0) {
int rc1, rc2;
rc1 = pcre_fullinfo(pce->re, extra, PCRE_INFO_NAMETABLE, &name_table);
rc2 = pcre_fullinfo(pce->re, extra, PCRE_INFO_NAMEENTRYSIZE, &name_size);
rc = rc2 ? rc2 : rc1;
if (rc < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
efree(subpat_names);
return NULL;
}
while (ni++ < name_cnt) {
name_idx = 0xff * (unsigned char)name_table[0] + (unsigned char)name_table[1];
subpat_names[name_idx] = name_table + 2;
if (is_numeric_string(subpat_names[name_idx], strlen(subpat_names[name_idx]), NULL, NULL, 0) > 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Numeric named subpatterns are not allowed");
efree(subpat_names);
return NULL;
}
name_table += name_size;
}
}
return subpat_names;
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
38 | static int pcre_clean_cache(void *data, void *arg TSRMLS_DC)
{
int *num_clean = (int *)arg;
if (*num_clean > 0) {
(*num_clean)--;
return 1;
} else {
return 0;
}
}
| DoS Overflow +Info | 0 | static int pcre_clean_cache(void *data, void *arg TSRMLS_DC)
{
int *num_clean = (int *)arg;
if (*num_clean > 0) {
(*num_clean)--;
return 1;
} else {
return 0;
}
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
39 | PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_options TSRMLS_DC)
{
pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex, strlen(regex) TSRMLS_CC);
if (extra) {
*extra = pce ? pce->extra : NULL;
}
if (preg_options) {
*preg_options = pce ? pce->preg_options : 0;
}
return pce ? pce->re : NULL;
}
| DoS Overflow +Info | 0 | PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_options TSRMLS_DC)
{
pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex, strlen(regex) TSRMLS_CC);
if (extra) {
*extra = pce ? pce->extra : NULL;
}
if (preg_options) {
*preg_options = pce ? pce->preg_options : 0;
}
return pce ? pce->re : NULL;
}
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
40 | PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC)
{
pcre *re = NULL;
pcre_extra *extra;
int coptions = 0;
int soptions = 0;
const char *error;
int erroffset;
char delimiter;
char start_delimiter;
char end_delimiter;
char *p, *pp;
char *pattern;
int do_study = 0;
int poptions = 0;
int count = 0;
unsigned const char *tables = NULL;
#if HAVE_SETLOCALE
char *locale;
#endif
pcre_cache_entry *pce;
pcre_cache_entry new_entry;
char *tmp = NULL;
#if HAVE_SETLOCALE
# if defined(PHP_WIN32) && defined(ZTS)
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
# endif
locale = setlocale(LC_CTYPE, NULL);
#endif
/* Try to lookup the cached regex entry, and if successful, just pass
back the compiled pattern, otherwise go on and compile it. */
if (zend_hash_find(&PCRE_G(pcre_cache), regex, regex_len+1, (void **)&pce) == SUCCESS) {
/*
* We use a quick pcre_fullinfo() check to see whether cache is corrupted, and if it
* is, we flush it and compile the pattern from scratch.
*/
if (pcre_fullinfo(pce->re, NULL, PCRE_INFO_CAPTURECOUNT, &count) == PCRE_ERROR_BADMAGIC) {
zend_hash_clean(&PCRE_G(pcre_cache));
} else {
#if HAVE_SETLOCALE
if (!strcmp(pce->locale, locale)) {
#endif
return pce;
#if HAVE_SETLOCALE
}
#endif
}
}
p = regex;
/* Parse through the leading whitespace, and display a warning if we
get to the end without encountering a delimiter. */
while (isspace((int)*(unsigned char *)p)) p++;
if (*p == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,
p < regex + regex_len ? "Null byte in regex" : "Empty regular expression");
return NULL;
}
/* Get the delimiter and display a warning if it is alphanumeric
or a backslash. */
delimiter = *p++;
if (isalnum((int)*(unsigned char *)&delimiter) || delimiter == '\\') {
php_error_docref(NULL TSRMLS_CC,E_WARNING, "Delimiter must not be alphanumeric or backslash");
return NULL;
}
start_delimiter = delimiter;
if ((pp = strchr("([{< )]}> )]}>", delimiter)))
| DoS Overflow +Info | 0 | PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC)
{
pcre *re = NULL;
pcre_extra *extra;
int coptions = 0;
int soptions = 0;
const char *error;
int erroffset;
char delimiter;
char start_delimiter;
char end_delimiter;
char *p, *pp;
char *pattern;
int do_study = 0;
int poptions = 0;
int count = 0;
unsigned const char *tables = NULL;
#if HAVE_SETLOCALE
char *locale;
#endif
pcre_cache_entry *pce;
pcre_cache_entry new_entry;
char *tmp = NULL;
#if HAVE_SETLOCALE
# if defined(PHP_WIN32) && defined(ZTS)
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
# endif
locale = setlocale(LC_CTYPE, NULL);
#endif
/* Try to lookup the cached regex entry, and if successful, just pass
back the compiled pattern, otherwise go on and compile it. */
if (zend_hash_find(&PCRE_G(pcre_cache), regex, regex_len+1, (void **)&pce) == SUCCESS) {
/*
* We use a quick pcre_fullinfo() check to see whether cache is corrupted, and if it
* is, we flush it and compile the pattern from scratch.
*/
if (pcre_fullinfo(pce->re, NULL, PCRE_INFO_CAPTURECOUNT, &count) == PCRE_ERROR_BADMAGIC) {
zend_hash_clean(&PCRE_G(pcre_cache));
} else {
#if HAVE_SETLOCALE
if (!strcmp(pce->locale, locale)) {
#endif
return pce;
#if HAVE_SETLOCALE
}
#endif
}
}
p = regex;
/* Parse through the leading whitespace, and display a warning if we
get to the end without encountering a delimiter. */
while (isspace((int)*(unsigned char *)p)) p++;
if (*p == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,
p < regex + regex_len ? "Null byte in regex" : "Empty regular expression");
return NULL;
}
/* Get the delimiter and display a warning if it is alphanumeric
or a backslash. */
delimiter = *p++;
if (isalnum((int)*(unsigned char *)&delimiter) || delimiter == '\\') {
php_error_docref(NULL TSRMLS_CC,E_WARNING, "Delimiter must not be alphanumeric or backslash");
return NULL;
}
start_delimiter = delimiter;
if ((pp = strchr("([{< )]}> )]}>", delimiter)))
| @@ -640,7 +640,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0); | CWE-119 | null | null |
MSR Data Cleaned - C/C++ Code Vulnerability Dataset
π Dataset Description
A curated collection of C/C++ code vulnerabilities paired with:
- CVE details (scores, classifications, exploit status)
- Code changes (commit messages, added/deleted lines)
- File-level and function-level diffs
π Sample Data Structure from original file
+---------------+-----------------+----------------------+---------------------------+
| CVE ID | Attack Origin | Publish Date | Summary |
+===============+=================+======================+===========================+
| CVE-2015-8467 | Remote | 2015-12-29 | "The samldb_check_user..."|
+---------------+-----------------+----------------------+---------------------------+
| CVE-2016-1234 | Local | 2016-01-15 | "Buffer overflow in..." |
+---------------+-----------------+----------------------+---------------------------+
Note: This is a simplified preview; the full dataset includes additional fields like commit_id, func_before, etc.
1. Accessing in Colab
!pip install huggingface_hub -q
from huggingface_hub import snapshot_download
repo_id = "starsofchance/MSR_data_cleaned"
dataset_path = snapshot_download(repo_id=repo_id, repo_type="dataset")
2. Extracting the Dataset
!apt-get install unzip -qq
!unzip "/root/.cache/huggingface/.../MSR_data_cleaned.zip" -d "/content/extracted_data"
**Note: Extracted size is 10GB (1.5GB compressed). Ensure sufficient disk space.
3. Creating Splits (Colab Pro Recommended)
We used this memory-efficient approach:
from datasets import load_dataset
dataset = load_dataset("csv", data_files="MSR_data_cleaned.csv", streaming=True)
# Randomly distribute rows (80-10-10)
for row in dataset:
rand = random.random()
if rand < 0.8: write_to(train.csv)
elif rand < 0.9: write_to(validation.csv)
else: write_to(test.csv)
Hardware Requirements:
- Minimum 25GB RAM
- Strong CPU (Colab Pro T4 GPU recommended)
##π Dataset Statistics
- Number of Rows: 188,636
- Vulnerability Distribution:
- Vulnerable (1): 18,863 (~10%)
- Non-Vulnerable (0): 169,773 (~90%)
##π Data Fields Description
- CVE_ID: Unique identifier for the vulnerability (Common Vulnerabilities and Exposures).
- CWE_ID: Weakness category identifier (Common Weakness Enumeration).
- Score: CVSS score indicating severity (float, 0-10).
- Summary: Brief description of the vulnerability.
- commit_id: Git commit hash linked to the code change.
- codeLink: URL to the code repository or commit.
- file_name: Name of the file containing the vulnerability.
- func_after: Function code after the change.
- lines_after: Code lines after the change.
- Access_Gained: Type of access gained by exploiting the vulnerability.
- Attack_Origin: Source of the attack (e.g., Remote, Local).
- Authentication_Required: Whether authentication is needed to exploit.
- Availability: Impact on system availability.
- CVE_Page: URL to the CVE details page.
- Complexity: Complexity of exploiting the vulnerability.
- Confidentiality: Impact on data confidentiality.
- Integrity: Impact on data integrity.
- Known_Exploits: Details of known exploits, if any.
- Publish_Date: Date the vulnerability was published.
- Update_Date: Date of the last update to the vulnerability data.
- Vulnerability_Classification: Type or category of the vulnerability.
- add_lines: Lines added in the commit.
- del_lines: Lines deleted in the commit.
- commit_message: Description of the commit.
- files_changed: List of files modified in the commit.
- func_before: Function code before the change.
- lang: Programming language (e.g., C, C++).
- lines_before: Code lines before the change.
splits file for UltiVul project:
π Sample Data Structure (from train.csv)
{
'idx': 0, # Unique ID within the train split
'func_before': '...', # String containing function code before change
'Vulnerability Classification': '...', # Original vulnerability type classification
'vul': 0, # Integer: 0 for non-vulnerable, 1 for vulnerable (target label)
'func_after': '...', # String containing function code after change
'patch': '...', # String containing diff patch
'CWE ID': '...', # String CWE ID, e.g., "CWE-119"
'lines_before': '...', # String lines before change context
'lines_after': '...' # String lines after change context
}
**Note: This shows the structure of the final split files (train.csv, validation.csv, test.csv). The original MSR_data_cleaned.csv contains many more metadata fields.
##π¦ Dataset New Files The dataset is available as three CSV files (specially created for the UltiVul project) hosted on Hugging Face, uploaded via huggingface_hub:
- train.csv Size: 667 MB Description: Training split with 150,909 samples, approximately 80% of the data.
- validation.csv Size: 86 MB Description: Validation split with 18,864 samples, approximately 10% of the data.
- test.csv Size: 84.8 MB Description: Test split with 18,863 samples, approximately 10% of the data.
π Acknowledgements Original dataset provided by Fan et al., 2020 Thanks to the Hugging Face team for dataset hosting tools.
π Citation
@inproceedings{fan2020ccode,
title={A C/C++ Code Vulnerability Dataset with Code Changes and CVE Summaries},
author={Fan, Jiahao and Li, Yi and Wang, Shaohua and Nguyen, Tien N},
booktitle={MSR '20: 17th International Conference on Mining Software Repositories},
pages={1--5},
year={2020},
doi={10.1145/3379597.3387501}
}
π Dataset Creation
- Source: Original data from MSR 2020 Paper
- Processing:
- Cleaned and standardized CSV format
- Stream-based splitting to handle large size
- Preserved all original metadata
- Downloads last month
- 33