samba-tool: fixed crash in "samba-tool drs showrepl"
authorAndrew Tridgell <tridge@samba.org>
Sun, 14 Nov 2010 21:27:04 +0000 (08:27 +1100)
committerAndrew Tridgell <tridge@samba.org>
Sun, 14 Nov 2010 23:19:34 +0000 (10:19 +1100)
the source_dsa_obj_dn can be NULL

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/samba_tool/drs/drs_showrepl.c

index f399097008a6ef4e9ce3d7be7188fad9b05810b0..5c095a89e674db09ce59447de4b55eb4e3348625 100644 (file)
@@ -46,7 +46,9 @@ static bool net_drs_parse_ntds_dn(struct ldb_dn *ntds_dn,
        NET_DRS_NOMEM_GOTO(dn, failed);
 
        /* remove NTDS Settings component */
        NET_DRS_NOMEM_GOTO(dn, failed);
 
        /* remove NTDS Settings component */
-       ldb_dn_remove_child_components(dn, 1);
+       if (!ldb_dn_remove_child_components(dn, 1)) {
+               return false;
+       }
        if (_dc_name) {
                val = ldb_dn_get_rdn_val(dn);
                *_dc_name = talloc_strdup(mem_ctx, (const char *)val->data);
        if (_dc_name) {
                val = ldb_dn_get_rdn_val(dn);
                *_dc_name = talloc_strdup(mem_ctx, (const char *)val->data);
@@ -82,12 +84,16 @@ failed:
        return false;
 }
 
        return false;
 }
 
-static char * net_drs_dc_canonical_string(struct ldb_dn *ntds_dn, TALLOC_CTX *mem_ctx)
+static const char * net_drs_dc_canonical_string(struct ldb_dn *ntds_dn, TALLOC_CTX *mem_ctx)
 {
        const char *dc_name;
        const char *site_name;
        char *canonical_name;
 
 {
        const char *dc_name;
        const char *site_name;
        char *canonical_name;
 
+       if (ldb_dn_is_null(ntds_dn)) {
+               return "(NULL DN)";
+       }
+
        if (!net_drs_parse_ntds_dn(ntds_dn, mem_ctx, &dc_name, &site_name, NULL)) {
                return NULL;
        }
        if (!net_drs_parse_ntds_dn(ntds_dn, mem_ctx, &dc_name, &site_name, NULL)) {
                return NULL;
        }
@@ -248,7 +254,7 @@ net_drs_transport_type_str(struct net_drs_context *drs_ctx, const char *transpor
  * Prints most of the info we got about
  * a replication partner
  */
  * Prints most of the info we got about
  * a replication partner
  */
-static bool net_drs_showrepl_print_heighbor(struct net_drs_context *drs_ctx,
+static bool net_drs_showrepl_print_neighbor(struct net_drs_context *drs_ctx,
                                            struct drsuapi_DsReplicaNeighbour *neighbor)
 {
        struct ldb_dn *ntds_dn;
                                            struct drsuapi_DsReplicaNeighbour *neighbor)
 {
        struct ldb_dn *ntds_dn;
@@ -309,7 +315,7 @@ static bool net_drs_showrepl_print_inbound_neihbors(struct net_drs_context *drs_
 
        for (i = 0; i < reps_from->count; i++) {
                d_printf("\n");
 
        for (i = 0; i < reps_from->count; i++) {
                d_printf("\n");
-               net_drs_showrepl_print_heighbor(drs_ctx, &reps_from->array[i]);
+               net_drs_showrepl_print_neighbor(drs_ctx, &reps_from->array[i]);
        }
 
        return true;
        }
 
        return true;
@@ -338,7 +344,7 @@ static bool net_drs_showrepl_print_outbound_neihbors(struct net_drs_context *drs
 
        for (i = 0; i < reps_to->count; i++) {
                d_printf("\n");
 
        for (i = 0; i < reps_to->count; i++) {
                d_printf("\n");
-               net_drs_showrepl_print_heighbor(drs_ctx, &reps_to->array[i]);
+               net_drs_showrepl_print_neighbor(drs_ctx, &reps_to->array[i]);
        }
 
        return true;
        }
 
        return true;