Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/utils/eventlogadm.c

    r740 r988  
    2626#include "lib/eventlog/eventlog.h"
    2727#include "registry.h"
     28#include "registry/reg_api.h"
     29#include "registry/reg_init_basic.h"
     30#include "registry/reg_util_token.h"
    2831#include "registry/reg_backend_db.h"
    29 #include "registry/reg_objects.h"
    3032#include "../libcli/registry/util_reg.h"
    3133
     
    7981        const char **wrklist, **wp;
    8082        char *evtlogpath = NULL;
    81         struct regsubkey_ctr *subkeys;
    82         struct regval_ctr *values;
    83         struct regval_blob *rval;
    8483        int ii = 0;
    8584        bool already_in;
    8685        int i;
    8786        int numsources = 0;
    88         TALLOC_CTX *ctx = talloc_tos();
     87        TALLOC_CTX *ctx = talloc_stackframe();
    8988        WERROR werr;
    90         DATA_BLOB blob;
     89        struct registry_key *key_hive, *key_eventlog, *key_source;
     90        struct security_token *token = NULL;
     91        const char *hive_name, *relpath;
     92        enum winreg_CreateAction action;
     93        struct registry_value *value;
     94        static const uint32_t ACCESS = REG_KEY_READ | REG_KEY_WRITE;
     95        bool ret = false;
    9196
    9297        if (!elogs) {
    93                 return False;
     98                d_printf("No Eventlogs configured\n");
     99                goto done;
    94100        }
    95101
     
    102108                d_printf("Eventlog [%s] not found in list of valid event logs\n",
    103109                         eventlog);
    104                 return false;   /* invalid named passed in */
     110                goto done;
    105111        }
    106112
     
    110116        /* todo add to Sources */
    111117
    112         werr = regval_ctr_init(ctx, &values);
    113         if(!W_ERROR_IS_OK(werr)) {
    114                 d_printf("talloc() failure!\n");
    115                 return false;
    116         }
    117 
    118118        evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog);
    119119        if (!evtlogpath) {
    120                 TALLOC_FREE(values);
    121                 return false;
    122         }
    123 
    124         regdb_fetch_values( evtlogpath, values );
    125 
    126 
    127         if ( !( rval = regval_ctr_getvalue( values, "Sources" ) ) ) {
    128                 d_printf("No Sources value for [%s]!\n", eventlog);
    129                 return False;
     120                d_printf("Out of memory\n");
     121                goto done;
     122        }
     123
     124        relpath = evtlogpath + sizeof(KEY_EVENTLOG);
     125        hive_name = talloc_strndup(ctx, evtlogpath, relpath - evtlogpath);
     126        if (!hive_name) {
     127                d_printf("Out of memory\n");
     128                goto done;
     129        }
     130        relpath++;
     131
     132        werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token));
     133        if (!W_ERROR_IS_OK(werr)) {
     134                d_printf("Failed to create admin token: %s\n", win_errstr(werr));
     135                goto done;
     136        }
     137
     138        werr = reg_openhive(ctx, hive_name, ACCESS, token, &key_hive);
     139        if (!W_ERROR_IS_OK(werr)) {
     140                d_printf("Failed to open hive [%s]: %s\n", hive_name, win_errstr(werr));
     141                goto done;
     142        }
     143
     144        werr = reg_openkey(ctx, key_hive, relpath, ACCESS, &key_eventlog);
     145        if (!W_ERROR_IS_OK(werr)) {
     146                d_printf("Failed to open key [%s]: %s\n", evtlogpath, win_errstr(werr));
     147                goto done;
     148        }
     149
     150        werr = reg_queryvalue(ctx, key_eventlog, "Sources", &value);
     151        if (!W_ERROR_IS_OK(werr)) {
     152                d_printf("Failed to get value \"Sources\" for [%s]: %s\n", evtlogpath, win_errstr(werr));
     153                goto done;
    130154        }
    131155        /* perhaps this adding a new string to a multi_sz should be a fn? */
    132156        /* check to see if it's there already */
    133157
    134         if ( regval_type(rval) != REG_MULTI_SZ ) {
    135                 d_printf("Wrong type for Sources, should be REG_MULTI_SZ\n");
    136                 return False;
     158        if ( value->type != REG_MULTI_SZ ) {
     159                d_printf("Wrong type for \"Sources\", should be REG_MULTI_SZ\n");
     160                goto done;
    137161        }
    138162        /* convert to a 'regulah' chars to do some comparisons */
    139163
    140         already_in = False;
     164        already_in = false;
    141165        wrklist = NULL;
    142         dump_data(1, regval_data_p(rval), regval_size(rval));
    143 
    144         blob = data_blob_const(regval_data_p(rval), regval_size(rval));
    145         if (!pull_reg_multi_sz(talloc_tos(), &blob, &wrklist)) {
    146                 return false;
     166        dump_data(1, value->data.data, value->data.length);
     167
     168        if (!pull_reg_multi_sz(ctx, &value->data, &wrklist)) {
     169                d_printf("Failed to pull REG_MULTI_SZ from \"Sources\"\n");
     170                goto done;
    147171        }
    148172
     
    159183                                d_printf("Source name [%s] already in list for [%s] \n",
    160184                                         sourcename, eventlog);
    161                                 already_in = True;
     185                                already_in = true;
    162186                                break;
    163187                        }
     
    168192        }
    169193
    170         wp = wrklist;
    171 
    172194        if ( !already_in ) {
    173195                /* make a new list with an additional entry; copy values, add another */
    174                 wp = TALLOC_ARRAY(ctx, const char *, numsources + 2 );
    175 
     196                wp = talloc_realloc(ctx, wrklist, const char *, numsources + 2 );
    176197                if ( !wp ) {
    177                         d_printf("talloc() failed \n");
    178                         return False;
    179                 }
    180                 memcpy( wp, wrklist, sizeof( char * ) * numsources );
    181                 *( wp + numsources ) = ( char * ) sourcename;
    182                 *( wp + numsources + 1 ) = NULL;
    183                 if (!push_reg_multi_sz(ctx, &blob, wp)) {
    184                         return false;
    185                 }
    186                 dump_data( 1, blob.data, blob.length);
    187                 regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
    188                                      blob.data, blob.length);
    189                 regdb_store_values( evtlogpath, values );
    190                 data_blob_free(&blob);
     198                        d_printf("Out of memory\n");
     199                        goto done;
     200                }
     201
     202                wp[numsources] = sourcename;
     203                wp[numsources+1] = NULL;
     204                if (!push_reg_multi_sz(ctx, &value->data, wp)) {
     205                        d_printf("Failed to push Sources\n");
     206                        goto done;
     207                }
     208                dump_data( 1, value->data.data, value->data.length);
     209                werr = reg_setvalue(key_eventlog,  "Sources", value);
     210                if (!W_ERROR_IS_OK(werr)) {
     211                        d_printf("Failed to set value Sources:  %s\n", win_errstr(werr));
     212                        goto done;
     213                }
    191214        } else {
    192215                d_printf("Source name [%s] found in existing list of sources\n",
    193216                         sourcename);
    194217        }
    195         TALLOC_FREE(values);
    196         TALLOC_FREE(wrklist);   /*  */
    197 
    198         werr = regsubkey_ctr_init(ctx, &subkeys);
    199         if (!W_ERROR_IS_OK(werr)) {
    200                 d_printf("talloc() failure!\n");
    201                 return False;
    202         }
    203         TALLOC_FREE(evtlogpath);
    204         evtlogpath = talloc_asprintf(ctx, "%s\\%s", KEY_EVENTLOG, eventlog );
    205         if (!evtlogpath) {
    206                 TALLOC_FREE(subkeys);
    207                 return false;
    208         }
    209 
    210         regdb_fetch_keys( evtlogpath, subkeys );
    211 
    212         if ( !regsubkey_ctr_key_exists( subkeys, sourcename ) ) {
     218
     219        werr = reg_createkey(ctx, key_eventlog, sourcename, ACCESS, &key_source, &action);
     220        if (!W_ERROR_IS_OK(werr)) {
     221                d_printf("Failed to create subkey \"%s\" of \"%s\": %s\n", sourcename, evtlogpath, win_errstr(werr));
     222                goto done;
     223        }
     224
     225        if (action == REG_CREATED_NEW_KEY) {
    213226                d_printf(" Source name [%s] for eventlog [%s] didn't exist, adding \n",
    214227                         sourcename, eventlog);
    215                 regsubkey_ctr_addkey( subkeys, sourcename );
    216                 if ( !regdb_store_keys( evtlogpath, subkeys ) )
    217                         return False;
    218         }
    219         TALLOC_FREE(subkeys);
     228        }
    220229
    221230        /* at this point KEY_EVENTLOG/<eventlog>/<sourcename> key is in there. Now need to add EventMessageFile */
    222231
    223         /* now allocate room for the source's subkeys */
    224 
    225         werr = regsubkey_ctr_init(ctx, &subkeys);
    226         if (!W_ERROR_IS_OK(werr)) {
    227                 d_printf("talloc() failure!\n");
    228                 return False;
    229         }
    230         TALLOC_FREE(evtlogpath);
    231         evtlogpath = talloc_asprintf(ctx, "%s\\%s\\%s",
    232                   KEY_EVENTLOG, eventlog, sourcename);
    233         if (!evtlogpath) {
    234                 TALLOC_FREE(subkeys);
    235                 return false;
    236         }
    237 
    238         regdb_fetch_keys( evtlogpath, subkeys );
    239 
    240232        /* now add the values to the KEY_EVENTLOG/Application form key */
    241         werr = regval_ctr_init(ctx, &values);
    242         if (!W_ERROR_IS_OK(werr)) {
    243                 d_printf("talloc() failure!\n");
    244                 return False;
    245         }
    246233        d_printf("Storing EventMessageFile [%s] to eventlog path of [%s]\n",
    247234                 messagefile, evtlogpath);
    248235
    249         regdb_fetch_values( evtlogpath, values );
    250 
    251         regval_ctr_addvalue_sz(values, "EventMessageFile", messagefile);
    252         regdb_store_values( evtlogpath, values );
    253 
    254         TALLOC_FREE(values);
    255 
    256         return True;
     236        if (!push_reg_sz(ctx, &value->data, messagefile)) {
     237                d_printf("Failed to push \"EventMessageFile\"\n");
     238                goto done;
     239        }
     240        value->type = REG_SZ;
     241
     242        werr = reg_setvalue(key_source, "EventMessageFile", value);
     243        if (!W_ERROR_IS_OK(werr)) {
     244                d_printf("Failed to set value \"EventMessageFile\":  %s\n", win_errstr(werr));
     245                return false;
     246        }
     247        ret = true;
     248done:
     249        talloc_free(ctx);
     250        return ret;
    257251}
    258252
    259253static int DoAddSourceCommand( int argc, char **argv, bool debugflag, char *exename )
    260254{
     255        WERROR werr;
    261256
    262257        if ( argc < 3 ) {
     
    265260                return -1;
    266261        }
     262
    267263        /* must open the registry before we access it */
    268         if (!W_ERROR_IS_OK(regdb_init())) {
    269                 printf( "Can't open the registry.\n" );
    270                 return -1;
    271         }
    272 
    273         if ( !eventlog_add_source( argv[0], argv[1], argv[2] ) )
     264        werr = registry_init_common();
     265        if (!W_ERROR_IS_OK(werr)) {
     266                printf("Can't open the registry: %s.\n", win_errstr(werr));
     267                return -1;
     268        }
     269        werr = regdb_transaction_start();
     270        if (!W_ERROR_IS_OK(werr)) {
     271                printf("Can't start transaction on registry: %s.\n", win_errstr(werr));
     272                return -1;
     273        }
     274
     275        if ( !eventlog_add_source( argv[0], argv[1], argv[2] ) ) {
     276                regdb_transaction_cancel();
    274277                return -2;
     278        }
     279        werr = regdb_transaction_commit();
     280        if (!W_ERROR_IS_OK(werr)) {
     281                printf("Failed to commit transaction on registry: %s.\n", win_errstr(werr));
     282                return -1;
     283        }
    275284        return 0;
    276285}
     
    366375        ELOG_TDB *etdb;
    367376        TALLOC_CTX *mem_ctx = talloc_tos();
    368         const char *tdb_filename;
    369377        uint32_t count = 1;
    370378
     
    372380                return -1;
    373381        }
    374 
    375         tdb_filename = argv[0];
    376382
    377383        if (argc > 1) {
     
    422428        fstring opname;
    423429
    424         load_case_tables();
     430        smb_init_locale();
    425431
    426432        opt_debug = 0;          /* todo set this from getopts */
     
    468474
    469475        if ( configfile == NULL ) {
    470                 lp_load(get_dyn_CONFIGFILE(), True, False, False, True);
    471         } else if (!lp_load(configfile, True, False, False, True)) {
     476                lp_load_global(get_dyn_CONFIGFILE());
     477        } else if (!lp_load_global(configfile)) {
    472478                printf("Unable to parse configfile '%s'\n",configfile);
    473479                exit( 1 );
     
    476482        /*  note that the separate command types should call usage if they need to... */
    477483        while ( 1 ) {
    478                 if ( !StrCaseCmp( opname, "addsource" ) ) {
     484                if ( !strcasecmp_m( opname, "addsource" ) ) {
    479485                        rc = DoAddSourceCommand( argc, argv, opt_debug,
    480486                                                 exename );
    481487                        break;
    482488                }
    483                 if ( !StrCaseCmp( opname, "write" ) ) {
     489                if ( !strcasecmp_m( opname, "write" ) ) {
    484490                        rc = DoWriteCommand( argc, argv, opt_debug, exename );
    485491                        break;
    486492                }
    487                 if ( !StrCaseCmp( opname, "dump" ) ) {
     493                if ( !strcasecmp_m( opname, "dump" ) ) {
    488494                        rc = DoDumpCommand( argc, argv, opt_debug, exename );
    489495                        break;
Note: See TracChangeset for help on using the changeset viewer.