Ignore:
Timestamp:
May 24, 2009, 7:51:24 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update Samba 3.3 branch to 3.3.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.3.x/source/registry/reg_objects.c

    r206 r223  
    2525#define DBGC_CLASS DBGC_REGISTRY
    2626
     27struct regsubkey_ctr {
     28        uint32_t        num_subkeys;
     29        char            **subkeys;
     30        struct db_context *subkeys_hash;
     31        int seqnum;
     32};
     33
    2734/**********************************************************************
    2835
    29  Note that the REGSUB_CTR and REGVAL_CTR objects *must* be talloc()'d
    30  since the methods use the object pointer as the talloc context for
    31  internal private data.
    32 
    33  There is no longer a regXXX_ctr_intit() and regXXX_ctr_destroy()
     36 Note that the struct regsubkey_ctr and REGVAL_CTR objects *must* be
     37 talloc()'d since the methods use the object pointer as the talloc
     38 context for internal private data.
     39
     40 There is no longer a regval_ctr_intit() and regval_ctr_destroy()
    3441 pair of functions.  Simply TALLOC_ZERO_P() and TALLOC_FREE() the
    3542 object.
     
    3744 **********************************************************************/
    3845
     46WERROR regsubkey_ctr_init(TALLOC_CTX *mem_ctx, struct regsubkey_ctr **ctr)
     47{
     48        if (ctr == NULL) {
     49                return WERR_INVALID_PARAM;
     50        }
     51
     52        *ctr = talloc_zero(mem_ctx, struct regsubkey_ctr);
     53        if (*ctr == NULL) {
     54                return WERR_NOMEM;
     55        }
     56
     57        (*ctr)->subkeys_hash = db_open_rbt(*ctr);
     58        if ((*ctr)->subkeys_hash == NULL) {
     59                talloc_free(*ctr);
     60                return WERR_NOMEM;
     61        }
     62
     63        return WERR_OK;
     64}
     65
     66WERROR regsubkey_ctr_set_seqnum(struct regsubkey_ctr *ctr, int seqnum)
     67{
     68        if (ctr == NULL) {
     69                return WERR_INVALID_PARAM;
     70        }
     71
     72        ctr->seqnum = seqnum;
     73
     74        return WERR_OK;
     75}
     76
     77int regsubkey_ctr_get_seqnum(struct regsubkey_ctr *ctr)
     78{
     79        if (ctr == NULL) {
     80                return -1;
     81        }
     82
     83        return ctr->seqnum;
     84}
     85
     86static WERROR regsubkey_ctr_hash_keyname(struct regsubkey_ctr *ctr,
     87                                         const char *keyname,
     88                                         uint32 idx)
     89{
     90        WERROR werr;
     91
     92        werr = ntstatus_to_werror(dbwrap_store_bystring(ctr->subkeys_hash,
     93                                                keyname,
     94                                                make_tdb_data((uint8 *)&idx,
     95                                                              sizeof(idx)),
     96                                                TDB_REPLACE));
     97        if (!W_ERROR_IS_OK(werr)) {
     98                DEBUG(1, ("error hashing new key '%s' in container: %s\n",
     99                          keyname, dos_errstr(werr)));
     100        }
     101
     102        return werr;
     103}
     104
     105static WERROR regsubkey_ctr_unhash_keyname(struct regsubkey_ctr *ctr,
     106                                           const char *keyname)
     107{
     108        WERROR werr;
     109
     110        werr = ntstatus_to_werror(dbwrap_delete_bystring(ctr->subkeys_hash,
     111                                  keyname));
     112        if (!W_ERROR_IS_OK(werr)) {
     113                DEBUG(1, ("error unhashing key '%s' in container: %s\n",
     114                          keyname, dos_errstr(werr)));
     115        }
     116
     117        return werr;
     118}
     119
     120static WERROR regsubkey_ctr_index_for_keyname(struct regsubkey_ctr *ctr,
     121                                              const char *keyname,
     122                                              uint32 *idx)
     123{
     124        TDB_DATA data;
     125
     126        if ((ctr == NULL) || (keyname == NULL)) {
     127                return WERR_INVALID_PARAM;
     128        }
     129
     130        data = dbwrap_fetch_bystring(ctr->subkeys_hash, ctr, keyname);
     131        if (data.dptr == NULL) {
     132                return WERR_NOT_FOUND;
     133        }
     134
     135        if (data.dsize != sizeof(*idx)) {
     136                talloc_free(data.dptr);
     137                return WERR_INVALID_DATATYPE;
     138        }
     139
     140        if (idx != NULL) {
     141                *idx = *(uint32 *)data.dptr;
     142        }
     143
     144        talloc_free(data.dptr);
     145        return WERR_OK;
     146}
     147
    39148/***********************************************************************
    40149 Add a new key to the array
    41150 **********************************************************************/
    42151
    43 WERROR regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, const char *keyname )
     152WERROR regsubkey_ctr_addkey( struct regsubkey_ctr *ctr, const char *keyname )
    44153{
    45154        char **newkeys;
     155        WERROR werr;
    46156
    47157        if ( !keyname ) {
     
    69179                return WERR_NOMEM;
    70180        }
     181
     182        werr = regsubkey_ctr_hash_keyname(ctr, keyname, ctr->num_subkeys);
     183        W_ERROR_NOT_OK_RETURN(werr);
     184
    71185        ctr->num_subkeys++;
    72186
     
    78192 **********************************************************************/
    79193
    80 int regsubkey_ctr_delkey( REGSUBKEY_CTR *ctr, const char *keyname )
    81 {
    82         int i;
    83 
    84         if ( !keyname )
    85                 return ctr->num_subkeys;
     194WERROR regsubkey_ctr_delkey( struct regsubkey_ctr *ctr, const char *keyname )
     195{
     196        WERROR werr;
     197        uint32 idx, j;
     198
     199        if (keyname == NULL) {
     200                return WERR_INVALID_PARAM;
     201        }
    86202
    87203        /* make sure the keyname is actually already there */
    88204
    89         for ( i=0; i<ctr->num_subkeys; i++ ) {
    90                 if ( strequal( ctr->subkeys[i], keyname ) )
    91                         break;
    92         }
    93 
    94         if ( i == ctr->num_subkeys )
    95                 return ctr->num_subkeys;
     205        werr = regsubkey_ctr_index_for_keyname(ctr, keyname, &idx);
     206        W_ERROR_NOT_OK_RETURN(werr);
     207
     208        werr = regsubkey_ctr_unhash_keyname(ctr, keyname);
     209        W_ERROR_NOT_OK_RETURN(werr);
    96210
    97211        /* update if we have any keys left */
    98212        ctr->num_subkeys--;
    99         if ( i < ctr->num_subkeys )
    100                 memmove(&ctr->subkeys[i], &ctr->subkeys[i+1],
    101                         sizeof(char*) * (ctr->num_subkeys-i));
    102 
    103         return ctr->num_subkeys;
     213        if (idx < ctr->num_subkeys) {
     214                memmove(&ctr->subkeys[idx], &ctr->subkeys[idx+1],
     215                        sizeof(char *) * (ctr->num_subkeys - idx));
     216
     217                /* we have to re-hash rest of the array...  :-( */
     218                for (j = idx; j < ctr->num_subkeys; j++) {
     219                        werr = regsubkey_ctr_hash_keyname(ctr, ctr->subkeys[j], j);
     220                        W_ERROR_NOT_OK_RETURN(werr);
     221                }
     222        }
     223
     224        return WERR_OK;
    104225}
    105226
     
    108229 **********************************************************************/
    109230
    110 bool regsubkey_ctr_key_exists( REGSUBKEY_CTR *ctr, const char *keyname )
    111 {
    112         int     i;
     231bool regsubkey_ctr_key_exists( struct regsubkey_ctr *ctr, const char *keyname )
     232{
     233        WERROR werr;
    113234
    114235        if (!ctr->subkeys) {
     
    116237        }
    117238
    118         for ( i=0; i<ctr->num_subkeys; i++ ) {
    119                 if ( strequal( ctr->subkeys[i],keyname ) )
    120                         return True;
    121         }
    122 
    123         return False;
     239        werr = regsubkey_ctr_index_for_keyname(ctr, keyname, NULL);
     240        if (!W_ERROR_IS_OK(werr)) {
     241                return false;
     242        }
     243
     244        return true;
    124245}
    125246
     
    128249 **********************************************************************/
    129250
    130 int regsubkey_ctr_numkeys( REGSUBKEY_CTR *ctr )
     251int regsubkey_ctr_numkeys( struct regsubkey_ctr *ctr )
    131252{
    132253        return ctr->num_subkeys;
     
    137258 **********************************************************************/
    138259
    139 char* regsubkey_ctr_specific_key( REGSUBKEY_CTR *ctr, uint32 key_index )
     260char* regsubkey_ctr_specific_key( struct regsubkey_ctr *ctr, uint32_t key_index )
    140261{
    141262        if ( ! (key_index < ctr->num_subkeys) )
Note: See TracChangeset for help on using the changeset viewer.