From: Matthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Date: Sat, 26 Sep 2009 15:16:06 +0000 (+0200)
Subject: s4: fix various warnings ("cast"/"const" related ones)
X-Git-Url: http://repo.or.cz/w/Samba/mdw.git?a=commitdiff_plain;h=32ad3118d946c347e1476bdf7291c7f1200d3c76

s4: fix various warnings ("cast"/"const" related ones)

I tried to add more "const"s or changed the "cast"s to fix some of them.
Where this hasn't been possible I added "discard_const_p" macro calls.

Sometimes I also removed unused variables.
---

diff --git a/source4/dsdb/samdb/cracknames.c b/source4/dsdb/samdb/cracknames.c
index 8f7f481..23811d3 100644
--- a/source4/dsdb/samdb/cracknames.c
+++ b/source4/dsdb/samdb/cracknames.c
@@ -23,15 +23,14 @@
 
 #include "includes.h"
 #include "librpc/gen_ndr/drsuapi.h"
-#include "rpc_server/common/common.h"
 #include "lib/events/events.h"
+#include "rpc_server/common/common.h"
 #include "lib/ldb/include/ldb.h"
 #include "lib/ldb/include/ldb_errors.h"
 #include "system/kerberos.h"
 #include "auth/kerberos/kerberos.h"
 #include "libcli/ldap/ldap_ndr.h"
 #include "libcli/security/security.h"
-#include "librpc/gen_ndr/ndr_misc.h"
 #include "auth/auth.h"
 #include "../lib/util/util_ldb.h"
 #include "dsdb/samdb/samdb.h"
@@ -55,7 +54,7 @@ static WERROR dns_domain_from_principal(TALLOC_CTX *mem_ctx, struct smb_krb5_con
 	krb5_error_code ret;
 	krb5_principal principal;
 	/* perhaps it's a principal with a realm, so return the right 'domain only' response */
-	char *realm;
+	const char *realm;
 	ret = krb5_parse_name_flags(smb_krb5_context->krb5_context, name, 
 				    KRB5_PRINCIPAL_PARSE_REQUIRE_REALM, &principal);
 	if (ret) {
@@ -271,7 +270,7 @@ static WERROR DsCrackNameUPN(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx,
 	const char *result_filter = NULL;
 	krb5_error_code ret;
 	krb5_principal principal;
-	char *realm;
+	const char *realm;
 	char *unparsed_name_short;
 	const char *domain_attrs[] = { NULL };
 	struct ldb_result *domain_res = NULL;
diff --git a/source4/dsdb/samdb/ldb_modules/acl.c b/source4/dsdb/samdb/ldb_modules/acl.c
index 2f12314..d015d0b 100644
--- a/source4/dsdb/samdb/ldb_modules/acl.c
+++ b/source4/dsdb/samdb/ldb_modules/acl.c
@@ -327,8 +327,9 @@ static int acl_access_check_add(struct ldb_reply *ares,
 		if (!oc_el || oc_el->num_values == 0)
 			return LDB_SUCCESS;
 		for (i = 0; i < oc_el->num_values; i++){
-			const struct GUID *guid = class_schemaid_guid_by_lDAPDisplayName(schema,
-											  oc_el->values[i].data);
+			const struct GUID *guid;
+			guid = class_schemaid_guid_by_lDAPDisplayName(schema,
+								      (const char *) oc_el->values[i].data);
 			ac->sec_result = LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS;
 			tree = insert_in_object_tree(ac->req, guid, NULL, SEC_ADS_CREATE_CHILD,
 						     tree);
@@ -359,13 +360,13 @@ static int acl_access_check_modify(struct ldb_reply *ares, struct acl_context *a
 		struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
 		const struct dsdb_schema *schema = dsdb_get_schema(ldb);
 		int i;
-		struct GUID *guid;
+		const struct GUID *guid;
 		oc_el = ldb_msg_find_element(ares->message, "objectClass");
 		if (!oc_el || oc_el->num_values == 0)
 			return LDB_SUCCESS;
 
 		guid = class_schemaid_guid_by_lDAPDisplayName(schema,
-							      oc_el->values[oc_el->num_values-1].data);
+							      (const char *) oc_el->values[oc_el->num_values-1].data);
 		tree = insert_in_object_tree(ac->req, guid, NULL, SEC_ADS_WRITE_PROP,
 						     tree);
 		for (i=0; i < ac->req->op.mod.message->num_elements; i++){
@@ -397,7 +398,6 @@ static int acl_access_check_delete(struct ldb_reply *ares, struct acl_context *a
 	uint32_t access_granted = 0;
 	NTSTATUS status;
 	struct ldb_dn *parent;
-	struct object_tree *tree = NULL;
 
 	parent = ldb_dn_get_parent(ac->req, ac->req->op.del.dn);
 	if (ldb_dn_compare(ares->message->dn, parent) == 0){
@@ -945,13 +945,13 @@ static int acl_search_callback(struct ldb_request *req, struct ldb_reply *ares)
 	uint32_t searchFlags;
 	uint32_t access_mask;
 	struct object_tree *ot;
-	int i, ret;
+	int i;
 	NTSTATUS status;
 	struct ldb_message_element *element_security_descriptor;
 	struct ldb_message_element *element_object_class;
 	const struct dsdb_attribute *attr;
 	const struct dsdb_schema *schema;
-	struct GUID *oc_guid;
+	const struct GUID *oc_guid;
 
 	ac = talloc_get_type(req->context, struct acl_context);
 	ldb = ldb_module_get_ctx(ac->module);
@@ -997,7 +997,8 @@ static int acl_search_callback(struct ldb_request *req, struct ldb_reply *ares)
 				return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR);
 			}
 
-			oc_guid = class_schemaid_guid_by_lDAPDisplayName(schema, element_object_class->values[0].data);
+			oc_guid = class_schemaid_guid_by_lDAPDisplayName(schema,
+									 (const char *) element_object_class->values[0].data);
 			for (i=0; i<ares->message->num_elements; i++) {
 				attr = dsdb_attribute_by_lDAPDisplayName(schema, ares->message->elements[i].name);
 				if (attr) {
@@ -1054,8 +1055,6 @@ static int acl_search(struct ldb_module *module, struct ldb_request *req)
 	struct ldb_context *ldb;
 	struct acl_context *ac;
 	const char **attrs;
-	struct ldb_control *sd_control;
-	struct ldb_control **sd_saved_controls;
 	struct ldb_dn * parent;
 	struct acl_private *data;
 
diff --git a/source4/dsdb/schema/schema.h b/source4/dsdb/schema/schema.h
index ddd9b37..3116492 100644
--- a/source4/dsdb/schema/schema.h
+++ b/source4/dsdb/schema/schema.h
@@ -134,10 +134,10 @@ struct dsdb_class {
 	bool isDefunct;
 	bool systemOnly;
 
-	char **supclasses;
-	char **subclasses;
-	char **subclasses_direct;
-	char **posssuperiors;
+	const char **supclasses;
+	const char **subclasses;
+	const char **subclasses_direct;
+	const char **posssuperiors;
 	uint32_t subClassOf_id;
 	uint32_t *systemAuxiliaryClass_ids;
 	uint32_t *auxiliaryClass_ids;
diff --git a/source4/dsdb/schema/schema_inferiors.c b/source4/dsdb/schema/schema_inferiors.c
index ecac74a..51c085f 100644
--- a/source4/dsdb/schema/schema_inferiors.c
+++ b/source4/dsdb/schema/schema_inferiors.c
@@ -34,15 +34,16 @@
 /*
   create the SUPCLASSES() list
  */
-static char **schema_supclasses(struct dsdb_schema *schema, struct dsdb_class *schema_class)
+static const char **schema_supclasses(const struct dsdb_schema *schema,
+				      struct dsdb_class *schema_class)
 {
-	char **list;
+	const char **list;
 
 	if (schema_class->supclasses) {
 		return schema_class->supclasses;
 	}
 
-	list = str_list_make_empty(schema_class);
+	list = (const char **) str_list_make_empty(schema_class);
 	if (list == NULL) {
 		DEBUG(0,(__location__ " out of memory\n"));
 		return NULL;
@@ -56,13 +57,11 @@ static char **schema_supclasses(struct dsdb_schema *schema, struct dsdb_class *s
 	}
 
 	if (schema_class->subClassOf) {
+		const struct dsdb_class *schema_class2 = dsdb_class_by_lDAPDisplayName(schema, schema_class->subClassOf);
 		const char **list2;
-		list = str_list_add_const(list, schema_class->subClassOf);
+		list = str_list_add_const(list,	schema_class->subClassOf);
 
-		list2 = schema_supclasses(schema,  
-					  discard_const_p(struct dsdb_class, 
-							  dsdb_class_by_lDAPDisplayName(schema, 
-											schema_class->subClassOf)));
+		list2 = schema_supclasses(schema, discard_const_p(struct dsdb_class, schema_class2));
 		list = str_list_append_const(list, list2);
 	}
 
@@ -75,13 +74,15 @@ static char **schema_supclasses(struct dsdb_schema *schema, struct dsdb_class *s
   this one is used internally
   matches SUBCLASSES() python function
  */
-static char **schema_subclasses(struct dsdb_schema *schema, TALLOC_CTX *mem_ctx, char **oclist)
+static const char **schema_subclasses(const struct dsdb_schema *schema,
+				      TALLOC_CTX *mem_ctx,
+				      const char **oclist)
 {
-	char **list = str_list_make_empty(mem_ctx);
+	const char **list = (const char **) str_list_make_empty(mem_ctx);
 	int i;
 
 	for (i=0; oclist && oclist[i]; i++) {
-		struct dsdb_class *schema_class = dsdb_class_by_lDAPDisplayName(schema, oclist[i]);
+		const struct dsdb_class *schema_class =	dsdb_class_by_lDAPDisplayName(schema, oclist[i]);
 		if (!schema_class) {
 			DEBUG(0, ("ERROR: Unable to locate subClass: '%s'\n", oclist[i]));
 			continue;
@@ -95,24 +96,25 @@ static char **schema_subclasses(struct dsdb_schema *schema, TALLOC_CTX *mem_ctx,
 /* 
    equivalent of the POSSSUPERIORS() python function
  */
-static char **schema_posssuperiors(struct dsdb_schema *schema, 
-				   struct dsdb_class *schema_class)
+static const char **schema_posssuperiors(const struct dsdb_schema *schema,
+					 struct dsdb_class *schema_class)
 {
 	if (schema_class->posssuperiors == NULL) {
-		char **list2 = str_list_make_empty(schema_class);
-		char **list3;
+		const char **list2 = (const char **) str_list_make_empty(schema_class);
+		const char **list3;
 		int i;
 
 		list2 = str_list_append_const(list2, schema_class->systemPossSuperiors);
 		list2 = str_list_append_const(list2, schema_class->possSuperiors);
 		list3 = schema_supclasses(schema, schema_class);
 		for (i=0; list3 && list3[i]; i++) {
-			struct dsdb_class *class2 = dsdb_class_by_lDAPDisplayName(schema, list3[i]);
+			const struct dsdb_class *class2 = dsdb_class_by_lDAPDisplayName(schema, list3[i]);
 			if (!class2) {
 				DEBUG(0, ("ERROR: Unable to locate supClass: '%s'\n", list3[i]));
 				continue;
 			}
-			list2 = str_list_append_const(list2, schema_posssuperiors(schema, class2));
+			list2 = str_list_append_const(list2, schema_posssuperiors(schema,
+				discard_const_p(struct dsdb_class, class2)));
 		}
 		list2 = str_list_append_const(list2, schema_subclasses(schema, list2, list2));
 
@@ -122,14 +124,16 @@ static char **schema_posssuperiors(struct dsdb_schema *schema,
 	return schema_class->posssuperiors;
 }
 
-static char **schema_subclasses_recurse(struct dsdb_schema *schema, struct dsdb_class *schema_class)
+static const char **schema_subclasses_recurse(const struct dsdb_schema *schema,
+					      struct dsdb_class *schema_class)
 {
-	char **list = str_list_copy_const(schema_class, schema_class->subclasses_direct);
+	const char **list = str_list_copy_const(schema_class, schema_class->subclasses_direct);
 	int i;
 	for (i=0;list && list[i]; i++) {
-		struct dsdb_class *schema_class2 = dsdb_class_by_lDAPDisplayName(schema, list[i]);
+		const struct dsdb_class *schema_class2 = dsdb_class_by_lDAPDisplayName(schema, list[i]);
 		if (schema_class != schema_class2) {
-			list = str_list_append_const(list, schema_subclasses_recurse(schema, schema_class2));
+			list = str_list_append_const(list, schema_subclasses_recurse(schema,
+				discard_const_p(struct dsdb_class, schema_class2)));
 		}
 	}
 	return list;
@@ -137,37 +141,40 @@ static char **schema_subclasses_recurse(struct dsdb_schema *schema, struct dsdb_
 
 /* Walk down the subClass tree, setting a higher index as we go down
  * each level.  top is 1, subclasses of top are 2, etc */
-void schema_subclasses_order_recurse(struct dsdb_schema *schema, struct dsdb_class *schema_class, int order)
+void schema_subclasses_order_recurse(const struct dsdb_schema *schema,
+				     struct dsdb_class *schema_class,
+				     const int order)
 {
 	const char **list = schema_class->subclasses_direct;
 	int i;
 	schema_class->subClass_order = order;
 	for (i=0;list && list[i]; i++) {
-		struct dsdb_class *schema_class2 = dsdb_class_by_lDAPDisplayName(schema, list[i]);
-		schema_subclasses_order_recurse(schema, schema_class2, order+1);
+		const struct dsdb_class *schema_class2 = dsdb_class_by_lDAPDisplayName(schema, list[i]);
+		schema_subclasses_order_recurse(schema, discard_const_p(struct dsdb_class, schema_class2), order+1);
 	}
 	return;
 }
 
-static int schema_create_subclasses(struct dsdb_schema *schema)
+static int schema_create_subclasses(const struct dsdb_schema *schema)
 {
 	struct dsdb_class *schema_class, *top;
 
 	for (schema_class=schema->classes; schema_class; schema_class=schema_class->next) {
-		struct dsdb_class *schema_class2 = dsdb_class_by_lDAPDisplayName(schema, schema_class->subClassOf);
+		struct dsdb_class *schema_class2 = discard_const_p(struct dsdb_class,
+			dsdb_class_by_lDAPDisplayName(schema, schema_class->subClassOf));
 		if (schema_class2 == NULL) {
 			DEBUG(0,("ERROR: no subClassOf for '%s'\n", schema_class->lDAPDisplayName));
 			return LDB_ERR_OPERATIONS_ERROR;
 		}
 		if (schema_class2 && schema_class != schema_class2) {
 			if (schema_class2->subclasses_direct == NULL) {
-				schema_class2->subclasses_direct = str_list_make_empty(schema_class2);
+				schema_class2->subclasses_direct = (const char **) str_list_make_empty(schema_class2);
 				if (!schema_class2->subclasses_direct) {
 					return LDB_ERR_OPERATIONS_ERROR;
 				}
 			}
-			schema_class2->subclasses_direct = str_list_add_const(schema_class2->subclasses_direct, 
-									schema_class->lDAPDisplayName);
+			schema_class2->subclasses_direct = str_list_add_const(schema_class2->subclasses_direct,
+						schema_class->lDAPDisplayName);
 		}
 	}
 
@@ -188,40 +195,42 @@ static int schema_create_subclasses(struct dsdb_schema *schema)
 	return LDB_SUCCESS;
 }
 
-static void schema_fill_possible_inferiors(struct dsdb_schema *schema, struct dsdb_class *schema_class)
+static void schema_fill_possible_inferiors(const struct dsdb_schema *schema,
+					   struct dsdb_class *schema_class)
 {
 	struct dsdb_class *c2;
 
 	for (c2=schema->classes; c2; c2=c2->next) {
-		char **superiors = schema_posssuperiors(schema, c2);
+		const char **superiors = schema_posssuperiors(schema, c2);
 		if (c2->systemOnly == false 
 		    && c2->objectClassCategory != 2 
 		    && c2->objectClassCategory != 3
 		    && str_list_check(superiors, schema_class->lDAPDisplayName)) {
 			if (schema_class->possibleInferiors == NULL) {
-				schema_class->possibleInferiors = str_list_make_empty(schema_class);
+				schema_class->possibleInferiors = (const char **) str_list_make_empty(schema_class);
 			}
 			schema_class->possibleInferiors = str_list_add_const(schema_class->possibleInferiors,
-								       c2->lDAPDisplayName);
+							c2->lDAPDisplayName);
 		}
 	}
 	schema_class->possibleInferiors = str_list_unique(schema_class->possibleInferiors);
 }
 
-static void schema_fill_system_possible_inferiors(struct dsdb_schema *schema, struct dsdb_class *schema_class)
+static void schema_fill_system_possible_inferiors(const struct dsdb_schema *schema,
+						  struct dsdb_class *schema_class)
 {
 	struct dsdb_class *c2;
 
 	for (c2=schema->classes; c2; c2=c2->next) {
-		char **superiors = schema_posssuperiors(schema, c2);
+		const char **superiors = schema_posssuperiors(schema, c2);
 		if (c2->objectClassCategory != 2
 		    && c2->objectClassCategory != 3
 		    && str_list_check(superiors, schema_class->lDAPDisplayName)) {
 			if (schema_class->systemPossibleInferiors == NULL) {
-				schema_class->systemPossibleInferiors = str_list_make_empty(schema_class);
+				schema_class->systemPossibleInferiors = (const char **)	str_list_make_empty(schema_class);
 			}
 			schema_class->systemPossibleInferiors = str_list_add_const(schema_class->systemPossibleInferiors,
-										   c2->lDAPDisplayName);
+							c2->lDAPDisplayName);
 		}
 	}
 	schema_class->systemPossibleInferiors = str_list_unique(schema_class->systemPossibleInferiors);
@@ -230,11 +239,14 @@ static void schema_fill_system_possible_inferiors(struct dsdb_schema *schema, st
 /*
   fill in a string class name from a governs_ID
  */
-static void schema_fill_from_class_one(struct dsdb_schema *schema, struct dsdb_class *c, 
-				    const char **s, uint32_t id)
+static void schema_fill_from_class_one(const struct dsdb_schema *schema,
+				       const struct dsdb_class *c,
+				       const char **s,
+				       const uint32_t id)
 {
 	if (*s == NULL && id != 0) {
-		struct dsdb_class *c2 = dsdb_class_by_governsID_id(schema, id);
+		const struct dsdb_class *c2 =
+					dsdb_class_by_governsID_id(schema, id);
 		if (c2) {
 			*s = c2->lDAPDisplayName;
 		}
@@ -244,15 +256,18 @@ static void schema_fill_from_class_one(struct dsdb_schema *schema, struct dsdb_c
 /*
   fill in a list of string class names from a governs_ID list
  */
-static void schema_fill_from_class_list(struct dsdb_schema *schema, struct dsdb_class *c, 
-				     const char ***s, uint32_t *ids)
+static void schema_fill_from_class_list(const struct dsdb_schema *schema,
+					const struct dsdb_class *c,
+					const char ***s,
+					const uint32_t *ids)
 {
 	if (*s == NULL && ids != NULL) {
 		int i;
 		for (i=0;ids[i];i++) ;
 		*s = talloc_array(c, const char *, i+1);
 		for (i=0;ids[i];i++) {
-			struct dsdb_class *c2 = dsdb_class_by_governsID_id(schema, ids[i]);
+			const struct dsdb_class *c2 =
+				dsdb_class_by_governsID_id(schema, ids[i]);
 			if (c2) {
 				(*s)[i] = c2->lDAPDisplayName;
 			} else {
@@ -266,15 +281,18 @@ static void schema_fill_from_class_list(struct dsdb_schema *schema, struct dsdb_
 /*
   fill in a list of string attribute names from a attributeID list
  */
-static void schema_fill_from_attribute_list(struct dsdb_schema *schema, struct dsdb_class *c, 
-					    const char ***s, uint32_t *ids)
+static void schema_fill_from_attribute_list(const struct dsdb_schema *schema,
+					    const struct dsdb_class *c,
+					    const char ***s,
+					    const uint32_t *ids)
 {
 	if (*s == NULL && ids != NULL) {
 		int i;
 		for (i=0;ids[i];i++) ;
 		*s = talloc_array(c, const char *, i+1);
 		for (i=0;ids[i];i++) {
-			struct dsdb_attribute *a = dsdb_attribute_by_attributeID_id(schema, ids[i]);
+			const struct dsdb_attribute *a =
+				dsdb_attribute_by_attributeID_id(schema, ids[i]);
 			if (a) {
 				(*s)[i] = a->lDAPDisplayName;
 			} else {
@@ -288,7 +306,7 @@ static void schema_fill_from_attribute_list(struct dsdb_schema *schema, struct d
 /*
   if the schema came from DRS then some attributes will be setup as IDs
  */
-static void schema_fill_from_ids(struct dsdb_schema *schema)
+static void schema_fill_from_ids(const struct dsdb_schema *schema)
 {
 	struct dsdb_class *c;
 	for (c=schema->classes; c; c=c->next) {
@@ -304,7 +322,7 @@ static void schema_fill_from_ids(struct dsdb_schema *schema)
 	}
 }
 
-int schema_fill_constructed(struct dsdb_schema *schema) 
+int schema_fill_constructed(const struct dsdb_schema *schema)
 {
 	int ret;
 	struct dsdb_class *schema_class;
@@ -332,5 +350,6 @@ int schema_fill_constructed(struct dsdb_schema *schema)
 		schema_class->subclasses = NULL;
 		schema_class->posssuperiors = NULL;
 	}
+
 	return LDB_SUCCESS;
 }
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 929f24c..0917325 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -896,14 +896,16 @@ int ldb_msg_check_string_attribute(const struct ldb_message *msg, const char *na
 	struct ldb_val val;
 	
 	el = ldb_msg_find_element(msg, name);
-	if (el == NULL)
-		return 0;
+	if (el == NULL) {
+		return LDB_SUCCESS;
+	}
 
 	val.data = discard_const_p(uint8_t, value);
 	val.length = strlen(value);
 
-	if (ldb_msg_find_val(el, &val))
-		return 1;
+	if (ldb_msg_find_val(el, &val)) {
+		return LDB_ERR_OPERATIONS_ERROR;
+	}
 
-	return 0;
+	return LDB_SUCCESS;
 }
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
index 52c1610..d11f2ba 100644
--- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c
+++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
@@ -107,14 +107,14 @@ static LDAPMod **lldb_msg_to_mods(void *mem_ctx, const struct ldb_message *msg,
 		mods[num_mods]->mod_vals.modv_bvals = talloc_array(mods[num_mods], 
 								   struct berval *,
 								   1+el->num_values);
-		if (!mods[num_mods]->mod_vals.modv_bvals) {
+		if (mods[num_mods]->mod_vals.modv_bvals == NULL) {
 			goto failed;
 		}
 
 		for (j=0;j<el->num_values;j++) {
 			mods[num_mods]->mod_vals.modv_bvals[j] = talloc(mods[num_mods]->mod_vals.modv_bvals,
 									struct berval);
-			if (!mods[num_mods]->mod_vals.modv_bvals[j]) {
+			if (mods[num_mods]->mod_vals.modv_bvals[j] == NULL) {
 				goto failed;
 			}
 			mods[num_mods]->mod_vals.modv_bvals[j]->bv_val = el->values[j].data;
@@ -254,7 +254,7 @@ static int lldb_search(struct lldb_context *lldb_ac)
 
 	ret = ldap_search_ext(lldb->ldap, search_base, ldap_scope, 
 			    expression, 
-			    discard_const_p(char *, req->op.search.attrs), 
+			    discard_const_p(char *, req->op.search.attrs),
 			    0,
 			    NULL,
 			    NULL,
diff --git a/source4/lib/ldb/ldb_map/ldb_map.c b/source4/lib/ldb/ldb_map/ldb_map.c
index 68e9d3f..65f4ed3 100644
--- a/source4/lib/ldb/ldb_map/ldb_map.c
+++ b/source4/lib/ldb/ldb_map/ldb_map.c
@@ -867,9 +867,14 @@ static int map_objectclass_convert_operator(struct ldb_module *module, void *mem
  * ============================== */
 
 /* Build a request to search a record by its DN. */
-struct ldb_request *map_search_base_req(struct map_context *ac, struct ldb_dn *dn, const char * const *attrs, const struct ldb_parse_tree *tree, void *context, ldb_map_callback_t callback)
+struct ldb_request *map_search_base_req(struct map_context *ac,
+					struct ldb_dn *dn,
+					const char * const *attrs,
+					struct ldb_parse_tree *tree,
+					void *context,
+					ldb_map_callback_t callback)
 {
-	const struct ldb_parse_tree *search_tree;
+	struct ldb_parse_tree *search_tree;
 	struct ldb_context *ldb;
 	struct ldb_request *req;
 	int ret;
diff --git a/source4/lib/ldb/ldb_map/ldb_map_private.h b/source4/lib/ldb/ldb_map/ldb_map_private.h
index 612d215..5d5baea 100644
--- a/source4/lib/ldb/ldb_map/ldb_map_private.h
+++ b/source4/lib/ldb/ldb_map/ldb_map_private.h
@@ -70,7 +70,7 @@ struct ldb_dn *ldb_dn_map_rebase_remote(struct ldb_module *module, void *mem_ctx
 struct ldb_request *map_search_base_req(struct map_context *ac,
 					struct ldb_dn *dn,
 					const char * const *attrs,
-					const struct ldb_parse_tree *tree,
+					struct ldb_parse_tree *tree,
 					void *context,
 					ldb_map_callback_t callback);
 struct ldb_request *map_build_fixup_req(struct map_context *ac,
diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c
index f0aea77..5d1431d 100644
--- a/source4/lib/ldb/modules/sort.c
+++ b/source4/lib/ldb/modules/sort.c
@@ -44,8 +44,8 @@ struct opaque {
 struct sort_context {
 	struct ldb_module *module;
 
-	char *attributeName;
-	char *orderingRule;
+	const char *attributeName;
+	const char *orderingRule;
 	int reverse;
 
 	struct ldb_request *req;
diff --git a/source4/libcli/security/access_check.c b/source4/libcli/security/access_check.c
index 543b0f7..628a106 100644
--- a/source4/libcli/security/access_check.c
+++ b/source4/libcli/security/access_check.c
@@ -182,7 +182,7 @@ NTSTATUS sec_access_check_ds(const struct security_descriptor *sd,
         int i;
         uint32_t bits_remaining;
         struct object_tree *node;
-        struct GUID *type;
+        const struct GUID *type;
 
         *access_granted = access_desired;
         bits_remaining = access_desired;
diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c
index 5c3efe2..125badf 100644
--- a/source4/nbt_server/wins/winsdb.c
+++ b/source4/nbt_server/wins/winsdb.c
@@ -320,7 +320,7 @@ static int ldb_msg_add_winsdb_addr(struct ldb_message *msg, struct winsdb_record
 				   const char *attr_name, struct winsdb_addr *addr)
 {
 	struct ldb_val val;
-	const char *str;
+	char *str;
 
 	if (rec->is_static) {
 		str = talloc_strdup(msg, addr->address);
@@ -336,7 +336,7 @@ static int ldb_msg_add_winsdb_addr(struct ldb_message *msg, struct winsdb_record
 		if (!str) return -1;
 	}
 
-	val.data = discard_const_p(uint8_t, str);
+	val.data = (uint8_t *) str;
 	val.length = strlen(str);
 
 	return ldb_msg_add_value(msg, attr_name, &val, NULL);
diff --git a/source4/ntvfs/posix/pvfs_resolve.c b/source4/ntvfs/posix/pvfs_resolve.c
index 8e8da72..06220a0 100644
--- a/source4/ntvfs/posix/pvfs_resolve.c
+++ b/source4/ntvfs/posix/pvfs_resolve.c
@@ -702,7 +702,7 @@ NTSTATUS pvfs_resolve_name_handle(struct pvfs_state *pvfs,
 			if (strcmp(h->name->full_name, name) != 0) {
 				const char *orig_dir;
 				const char *new_file;
-				const char *new_orig;
+				char *new_orig;
 				char *delim;
 
 				delim = strrchr(name, '/');
@@ -732,7 +732,12 @@ NTSTATUS pvfs_resolve_name_handle(struct pvfs_state *pvfs,
 
 				talloc_free(h->name->original_name);
 				talloc_free(h->name->full_name);
-				h->name->full_name = talloc_steal(h->name, name);
+				h->name->full_name = talloc_strdup(h->name,
+									name);
+				if (!h->name->full_name) {
+					talloc_free(lck);
+					return NT_STATUS_NO_MEMORY;
+				}
 				h->name->original_name = new_orig;
 			}
 		}
diff --git a/source4/ntvfs/posix/vfs_posix.h b/source4/ntvfs/posix/vfs_posix.h
index b032ab3..508dbb0 100644
--- a/source4/ntvfs/posix/vfs_posix.h
+++ b/source4/ntvfs/posix/vfs_posix.h
@@ -124,7 +124,7 @@ struct pvfs_dos_fileinfo {
   a filename passed by the client to any function
 */
 struct pvfs_filename {
-	const char *original_name;
+	char *original_name;
 	char *full_name;
 	const char *stream_name; /* does not include :$DATA suffix */
 	uint32_t stream_id;      /* this uses a hash, so is probabilistic */
diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c
index 882de13..bb852c6 100644
--- a/source4/param/loadparm.c
+++ b/source4/param/loadparm.c
@@ -1964,8 +1964,8 @@ static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
 			return (*((int *)ptr1) == *((int *)ptr2));
 
 		case P_LIST:
-			return str_list_equal((const char **)(*(char ***)ptr1),
-					      (const char **)(*(char ***)ptr2));
+			return str_list_equal((const char * const *)(*(char ***)ptr1),
+					      (const char * const *)(*(char ***)ptr2));
 
 		case P_STRING:
 		case P_USTRING:
@@ -2041,8 +2041,8 @@ static bool is_default(struct loadparm_service *sDefault, int i)
 		return false;
 	switch (parm_table[i].type) {
 		case P_LIST:
-			return str_list_equal((const char **)parm_table[i].def.lvalue, 
-					      (const char **)def_ptr);
+			return str_list_equal((const char * const *)parm_table[i].def.lvalue,
+					      (const char * const *)def_ptr);
 		case P_STRING:
 		case P_USTRING:
 			return strequal(parm_table[i].def.svalue,
diff --git a/source4/torture/ldap/ldap_sort.c b/source4/torture/ldap/ldap_sort.c
index 4d732cf..cbde455 100644
--- a/source4/torture/ldap/ldap_sort.c
+++ b/source4/torture/ldap/ldap_sort.c
@@ -46,13 +46,13 @@ bool torture_ldap_sort(struct torture_context *torture)
 	struct ldb_server_sort_control **control;
 	struct ldb_request *req;
 	struct ldb_result *ctx;
-	struct ldb_val* prev = NULL;
+	struct ldb_val *prev = NULL;
 	const char *prev_txt = NULL;
 	int prev_len = 0;
-	struct ldb_val* cur = NULL;
+	struct ldb_val *cur = NULL;
 	const char *cur_txt = NULL;
 	int cur_len = 0;
-	struct ldb_dn* dn;
+	struct ldb_dn *dn;
 		 
 		 
 	/* TALLOC_CTX* ctx;*/
@@ -103,10 +103,10 @@ bool torture_ldap_sort(struct torture_context *torture)
 			if (prev != NULL)
 			{
 				/* Do only the ascii case right now ... */
-				cur_txt=cur->data;
-				cur_len=cur->length;
-				prev_txt=prev->data;
-				prev_len=prev->length;
+				cur_txt = (const char *) cur->data;
+				cur_len = cur->length;
+				prev_txt = (const char *) prev->data;
+				prev_len = prev->length;
 				/* Remove leading whitespace as the sort function do so ... */
 				while ( cur_txt[0] == cur_txt[1] ) { cur_txt++; cur_len--;}
 				while ( prev_txt[0] == prev_txt[1] ) { prev_txt++; prev_len--;}
diff --git a/source4/torture/ldb/ldb.c b/source4/torture/ldb/ldb.c
index 23c9bb2..cad845c 100644
--- a/source4/torture/ldb/ldb.c
+++ b/source4/torture/ldb/ldb.c
@@ -665,8 +665,9 @@ static bool torture_ldb_dn(struct torture_context *torture)
 		       ldb_dn_validate(dn) == false,
 		       "should have failed to validate a DN with 0xA in it");
 
-	val.data = "CN=Zer\0,DC=SAMBA,DC=org";
+	val.data = discard_const_p(uint8_t, "CN=Zer\0,DC=SAMBA,DC=org");
 	val.length = 23;
+
 	torture_assert(torture,
 		       NULL == ldb_dn_from_ldb_val(mem_ctx, ldb, &val),
 		       "should fail to create a DN with 0x0 in it");
diff --git a/source4/torture/nbench/nbench.c b/source4/torture/nbench/nbench.c
index 5a4037f..820223f 100644
--- a/source4/torture/nbench/nbench.c
+++ b/source4/torture/nbench/nbench.c
@@ -99,7 +99,8 @@ again:
 
 		all_string_sub(line,"client1", cname, sizeof(line));
 		
-		params = params0 = str_list_make_shell(NULL, line, " ");
+		params = params0 = (const char **)
+					str_list_make_shell(NULL, line, " ");
 		i = str_list_length(params);
 
 		if (i > 0 && isdigit(params[0][0])) {
diff --git a/source4/torture/nbt/wins.c b/source4/torture/nbt/wins.c
index 13dc066..777cfa1 100644
--- a/source4/torture/nbt/wins.c
+++ b/source4/torture/nbt/wins.c
@@ -117,8 +117,10 @@ static bool nbt_test_wins_name(struct torture_context *tctx, const char *address
 		torture_comment(tctx, "register the name with a wrong address (makes the next request slow!)\n");
 		io.in.name = *name;
 		io.in.wins_port = lp_nbt_port(tctx->lp_ctx);
-		io.in.wins_servers = str_list_make_single(tctx, address);
-		io.in.addresses = str_list_make_single(tctx, "127.64.64.1");
+		io.in.wins_servers = (const char **)
+			str_list_make_single(tctx, address);
+		io.in.addresses = (const char **)
+			str_list_make_single(tctx, "127.64.64.1");
 		io.in.nb_flags = nb_flags;
 		io.in.ttl = 300000;
 
@@ -311,8 +313,10 @@ static bool nbt_test_wins_name(struct torture_context *tctx, const char *address
 		torture_comment(tctx, "register the name with a wrong address (makes the next request slow!)\n");
 		io.in.name = *name;
 		io.in.wins_port = lp_nbt_port(tctx->lp_ctx);
-		io.in.wins_servers = str_list_make_single(tctx, address);
-		io.in.addresses = str_list_make_single(tctx, "127.64.64.1");
+		io.in.wins_servers = (const char **)
+			str_list_make_single(tctx, address);
+		io.in.addresses = (const char **)
+			str_list_make_single(tctx, "127.64.64.1");
 		io.in.nb_flags = nb_flags;
 		io.in.ttl = 300000;
 	
@@ -333,8 +337,10 @@ static bool nbt_test_wins_name(struct torture_context *tctx, const char *address
 	torture_comment(tctx, "refresh the name with the correct address\n");
 	refresh.in.name = *name;
 	refresh.in.wins_port = lp_nbt_port(tctx->lp_ctx);
-	refresh.in.wins_servers = str_list_make_single(tctx, address);
-	refresh.in.addresses = str_list_make_single(tctx, myaddress);
+	refresh.in.wins_servers = (const char **)
+			str_list_make_single(tctx, address);
+	refresh.in.addresses = (const char **)
+			str_list_make_single(tctx, myaddress);
 	refresh.in.nb_flags = nb_flags;
 	refresh.in.ttl = 12345;
 
diff --git a/source4/torture/raw/lock.c b/source4/torture/raw/lock.c
index 0228837..7b7b955 100644
--- a/source4/torture/raw/lock.c
+++ b/source4/torture/raw/lock.c
@@ -1326,7 +1326,7 @@ struct double_lock_test {
 /**
  * Tests zero byte locks.
  */
-static const struct double_lock_test zero_byte_tests[] = {
+static struct double_lock_test zero_byte_tests[] = {
 	/* {pid, offset, count}, {pid, offset, count}, status */
 
 	/** First, takes a zero byte lock at offset 10. Then:
diff --git a/source4/torture/raw/samba3misc.c b/source4/torture/raw/samba3misc.c
index e8dc12f..2e85a34 100644
--- a/source4/torture/raw/samba3misc.c
+++ b/source4/torture/raw/samba3misc.c
@@ -1007,7 +1007,7 @@ bool torture_samba3_oplock_logoff(struct torture_context *tctx)
 
 	echo_req.in.repeat_count = 1;
 	echo_req.in.size = 1;
-	echo_req.in.data = (uint8_t *)"";
+	echo_req.in.data = discard_const_p(uint8_t, "");
 
 	status = smb_raw_echo(cli->session->transport, &echo_req);
 	if (!NT_STATUS_IS_OK(status)) {
diff --git a/source4/torture/rpc/wkssvc.c b/source4/torture/rpc/wkssvc.c
index d5ef0a4..1c16f78 100644
--- a/source4/torture/rpc/wkssvc.c
+++ b/source4/torture/rpc/wkssvc.c
@@ -966,7 +966,7 @@ static bool test_NetrMessageBufferSend(struct torture_context *tctx,
 	size_t size;
 	uint8_t *msg;
 
-	push_ucs2_talloc(tctx, (void **)&msg, message, &size);
+	push_ucs2_talloc(tctx, (smb_ucs2_t **)&msg, message, &size);
 
 	r.in.server_name = dcerpc_server_name(p);
 	r.in.message_name = dcerpc_server_name(p);
diff --git a/source4/torture/smbtorture.c b/source4/torture/smbtorture.c
index 08c5748..c8c4290 100644
--- a/source4/torture/smbtorture.c
+++ b/source4/torture/smbtorture.c
@@ -514,7 +514,7 @@ int main(int argc,char *argv[])
 			{
 				char *option = talloc_asprintf(NULL, "torture:extra_user%u",
 							       ++num_extra_users);
-				char *value = poptGetOptArg(pc);
+				const char *value = poptGetOptArg(pc);
 				lp_set_cmdline(cmdline_lp_ctx, option, value);
 				talloc_free(option);
 			}
