7f8f664ec6e196aee4bf9f1aab30328eb7350319
[vlendec/samba-autobuild/.git] / source3 / registry / reg_dynamic.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  Virtual Windows Registry Layer
4  *  Copyright (C) Gerald Carter                     2002-2005
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 /* Implementation of registry frontend view functions. */
22
23 #include "includes.h"
24
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_RPC_SRV
27
28 struct reg_dyn_values {
29         const char *path;
30         int (*fetch_values) ( REGVAL_CTR *val );
31 };
32
33 /***********************************************************************
34 ***********************************************************************/
35
36 static int netlogon_params( REGVAL_CTR *regvals )
37 {
38         uint32 dwValue;
39         
40         if ( !account_policy_get(AP_REFUSE_MACHINE_PW_CHANGE, &dwValue) )
41                 dwValue = 0;
42                 
43         regval_ctr_addvalue( regvals, "RefusePasswordChange", REG_DWORD,
44                 (char*)&dwValue, sizeof(dwValue) );
45
46         return regval_ctr_numvals( regvals );
47 }
48
49 /***********************************************************************
50 ***********************************************************************/
51
52 static int prod_options( REGVAL_CTR *regvals )
53 {
54         const char              *value_ascii = "";
55         fstring                 value;
56         int                     value_length;
57         
58         switch (lp_server_role()) {
59                 case ROLE_DOMAIN_PDC:
60                 case ROLE_DOMAIN_BDC:
61                         value_ascii = "LanmanNT";
62                         break;
63                 case ROLE_STANDALONE:
64                         value_ascii = "ServerNT";
65                         break;
66                 case ROLE_DOMAIN_MEMBER:
67                         value_ascii = "WinNT";
68                         break;
69         }
70                 
71         value_length = push_ucs2( value, value, value_ascii, sizeof(value), 
72                 STR_TERMINATE|STR_NOALIGN );
73         regval_ctr_addvalue( regvals, "ProductType", REG_SZ, value, 
74                 value_length );
75         
76         return regval_ctr_numvals( regvals );
77 }
78
79 /***********************************************************************
80 ***********************************************************************/
81
82 static int tcpip_params( REGVAL_CTR *regvals )
83 {
84         fstring                 value;
85         int                     value_length;
86         char                    *hname;
87         fstring                 mydomainname;
88         
89
90         hname = myhostname();
91         value_length = push_ucs2( value, value, hname, sizeof(value), STR_TERMINATE|STR_NOALIGN);               
92         regval_ctr_addvalue( regvals, "Hostname",REG_SZ, value, value_length );
93         
94         get_mydnsdomname( mydomainname );               
95         value_length = push_ucs2( value, value, mydomainname, sizeof(value), STR_TERMINATE|STR_NOALIGN);                
96         regval_ctr_addvalue( regvals, "Domain", REG_SZ, value, value_length );
97                 
98         return regval_ctr_numvals( regvals );
99 }
100
101
102 /***********************************************************************
103  Structure holding the registry paths and pointers to the value 
104  enumeration functions
105 ***********************************************************************/
106
107 static struct reg_dyn_values dynamic_values[] = {
108         { "HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/NETLOGON/PARAMETERS", &netlogon_params  },
109         { "HKLM/SYSTEM/CURRENTCONTROLSET/CONTROL/PRODUCTOPTIONS",       &prod_options     },
110         { "HKLM/SYSTEM/CURRENTCONTROLSET/SERVICES/TCPIP/PARAMETERS",    &tcpip_params     },
111         { NULL, NULL }
112 };
113
114 /***********************************************************************
115 ***********************************************************************/
116
117 int fetch_dynamic_reg_values( REGISTRY_KEY *key, REGVAL_CTR *val )
118 {
119         int i;
120         pstring path;
121         
122         pstrcpy( path, key->name );
123         normalize_reg_path( path );
124         
125         for ( i=0; dynamic_values[i].path; i++ ) {
126                 if ( strcmp( path, dynamic_values[i].path ) == 0 )
127                         return dynamic_values[i].fetch_values( val );
128         }
129         
130         return -1;
131 }
132
133 /***********************************************************************
134 ***********************************************************************/
135
136 BOOL check_dynamic_reg_values( REGISTRY_KEY *key )
137 {
138         int i;
139         pstring path;
140         
141         pstrcpy( path, key->name );
142         normalize_reg_path( path );
143         
144         for ( i=0; dynamic_values[i].path; i++ ) {
145                 /* can't write to dynamic keys */
146                 if ( strcmp( path, dynamic_values[i].path ) == 0 )
147                         return True;
148         }
149         
150         return False;
151 }
152