r10909: Give better shutdown messages
[Samba/bb.git] / source3 / registry / reg_eventlog.c
blob204c4c6e1c21ef3a8da5722fc79c84b282fd51a9
1 /*
2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 * Copyright (C) Marcin Krzysztof Porwit 2005,
5 * Copyright (C) Brian Moran 2005.
6 * Copyright (C) Gerald (Jerry) Carter 2005.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
26 /**********************************************************************
27 for an eventlog, add in the default values
28 *********************************************************************/
30 BOOL eventlog_init_keys( void )
32 /* Find all of the eventlogs, add keys for each of them */
33 const char **elogs = lp_eventlog_list( );
34 pstring evtlogpath;
35 REGSUBKEY_CTR *subkeys;
36 REGVAL_CTR *values;
37 uint32 uiDisplayNameId;
38 uint32 uiMaxSize;
39 uint32 uiRetention;
40 uint32 uiCategoryCount;
41 UNISTR2 data;
43 while ( elogs && *elogs ) {
44 if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
45 DEBUG( 0, ( "talloc() failure!\n" ) );
46 return False;
48 regdb_fetch_keys( KEY_EVENTLOG, subkeys );
49 regsubkey_ctr_addkey( subkeys, *elogs );
50 if ( !regdb_store_keys( KEY_EVENTLOG, subkeys ) )
51 return False;
52 TALLOC_FREE( subkeys );
54 /* add in the key of form KEY_EVENTLOG/Application */
55 DEBUG( 5,
56 ( "Adding key of [%s] to path of [%s]\n", *elogs,
57 KEY_EVENTLOG ) );
59 slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s",
60 KEY_EVENTLOG, *elogs );
61 /* add in the key of form KEY_EVENTLOG/Application/Application */
62 DEBUG( 5,
63 ( "Adding key of [%s] to path of [%s]\n", *elogs,
64 evtlogpath ) );
65 if ( !( subkeys = TALLOC_ZERO_P( NULL, REGSUBKEY_CTR ) ) ) {
66 DEBUG( 0, ( "talloc() failure!\n" ) );
67 return False;
69 regdb_fetch_keys( evtlogpath, subkeys );
70 regsubkey_ctr_addkey( subkeys, *elogs );
72 if ( !regdb_store_keys( evtlogpath, subkeys ) )
73 return False;
74 TALLOC_FREE( subkeys );
76 /* now add the values to the KEY_EVENTLOG/Application form key */
77 if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
78 DEBUG( 0, ( "talloc() failure!\n" ) );
79 return False;
81 DEBUG( 5,
82 ( "Storing values to eventlog path of [%s]\n",
83 evtlogpath ) );
84 regdb_fetch_values( evtlogpath, values );
86 if ( !regval_ctr_key_exists( values, "MaxSize" ) ) {
87 /* assume we have none, add them all */
89 /* hard code some initial values */
91 uiDisplayNameId = 0x00000100;
92 uiMaxSize = 0x00080000;
93 uiRetention = 0x93A80;
95 regval_ctr_addvalue( values, "MaxSize", REG_DWORD,
96 ( char * ) &uiMaxSize,
97 sizeof( uint32 ) );
98 regval_ctr_addvalue( values, "Retention", REG_DWORD,
99 ( char * ) &uiRetention,
100 sizeof( uint32 ) );
101 init_unistr2( &data, *elogs, UNI_STR_TERMINATE );
102 regval_ctr_addvalue( values, "PrimaryModule", REG_SZ,
103 ( char * ) data.buffer,
104 data.uni_str_len *
105 sizeof( uint16 ) );
106 init_unistr2( &data, *elogs, UNI_STR_TERMINATE );
108 regval_ctr_addvalue( values, "Sources", REG_MULTI_SZ,
109 ( char * ) data.buffer,
110 data.uni_str_len *
111 sizeof( uint16 ) );
112 regdb_store_values( evtlogpath, values );
116 TALLOC_FREE( values );
118 /* now do the values under KEY_EVENTLOG/Application/Application */
119 slprintf( evtlogpath, sizeof( evtlogpath ) - 1, "%s\\%s\\%s",
120 KEY_EVENTLOG, *elogs, *elogs );
121 if ( !( values = TALLOC_ZERO_P( NULL, REGVAL_CTR ) ) ) {
122 DEBUG( 0, ( "talloc() failure!\n" ) );
123 return False;
125 DEBUG( 5,
126 ( "Storing values to eventlog path of [%s]\n",
127 evtlogpath ) );
128 regdb_fetch_values( evtlogpath, values );
129 if ( !regval_ctr_key_exists( values, "CategoryCount" ) ) {
131 /* hard code some initial values */
133 uiCategoryCount = 0x00000007;
134 regval_ctr_addvalue( values, "CategoryCount",
135 REG_DWORD,
136 ( char * ) &uiCategoryCount,
137 sizeof( uint32 ) );
138 init_unistr2( &data,
139 "%SystemRoot%\\system32\\eventlog.dll",
140 UNI_STR_TERMINATE );
142 regval_ctr_addvalue( values, "CategoryMessageFile",
143 REG_EXPAND_SZ,
144 ( char * ) data.buffer,
145 data.uni_str_len *
146 sizeof( uint16 ) );
147 regdb_store_values( evtlogpath, values );
149 TALLOC_FREE( values );
150 elogs++;
152 return True;