r23801: The FSF has moved around a lot. This fixes their Mass Ave address.
[nivanova/samba-autobuild/.git] / source3 / rpc_server / srv_ntsvcs_nt.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *
5  *  Copyright (C) Gerald (Jerry) Carter             2005.
6  *  
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 3 of the License, or
10  *  (at your option) any later version.
11  *  
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *  
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include "includes.h"
22
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_RPC_SRV
25
26 /********************************************************************
27 ********************************************************************/
28
29 static char* get_device_path(TALLOC_CTX *mem_ctx, const char *device )
30 {
31         return talloc_asprintf(mem_ctx, "ROOT\\Legacy_%s\\0000", device);
32 }
33
34 /********************************************************************
35 ********************************************************************/
36
37 WERROR _ntsvcs_get_version( pipes_struct *p, NTSVCS_Q_GET_VERSION *q_u, NTSVCS_R_GET_VERSION *r_u )
38 {
39         r_u->version = 0x00000400;      /* no idea what this means */
40                 
41         return WERR_OK;
42 }
43
44 /********************************************************************
45 ********************************************************************/
46
47 WERROR _ntsvcs_get_device_list_size( pipes_struct *p, NTSVCS_Q_GET_DEVICE_LIST_SIZE *q_u, NTSVCS_R_GET_DEVICE_LIST_SIZE *r_u )
48 {
49         fstring device;
50         char *devicepath;
51
52         if ( !q_u->devicename )
53                 return WERR_ACCESS_DENIED;
54
55         rpcstr_pull(device, q_u->devicename->buffer, sizeof(device), q_u->devicename->uni_str_len*2, 0);
56
57         if (!(devicepath = get_device_path(p->mem_ctx, device))) {
58                 return WERR_NOMEM;
59         }
60
61         r_u->size = strlen(devicepath) + 2;
62
63         TALLOC_FREE(devicepath);
64
65         return WERR_OK;
66 }
67
68
69 /********************************************************************
70 ********************************************************************/
71
72 WERROR _ntsvcs_get_device_list( pipes_struct *p, NTSVCS_Q_GET_DEVICE_LIST *q_u, NTSVCS_R_GET_DEVICE_LIST *r_u )
73 {
74         fstring device;
75         char *devicepath;
76
77         if ( !q_u->devicename )
78                 return WERR_ACCESS_DENIED;
79
80         rpcstr_pull(device, q_u->devicename->buffer, sizeof(device), q_u->devicename->uni_str_len*2, 0);
81
82         if (!(devicepath = get_device_path(p->mem_ctx, device))) {
83                 return WERR_NOMEM;
84         }
85
86         /* This has to be DOUBLE NULL terminated */
87
88         init_unistr2( &r_u->devicepath, devicepath, UNI_STR_DBLTERMINATE );
89         TALLOC_FREE(devicepath);
90         r_u->needed = r_u->devicepath.uni_str_len;
91
92         return WERR_OK;
93 }
94
95 /********************************************************************
96 ********************************************************************/
97
98 WERROR _ntsvcs_get_device_reg_property( pipes_struct *p, NTSVCS_Q_GET_DEVICE_REG_PROPERTY *q_u, NTSVCS_R_GET_DEVICE_REG_PROPERTY *r_u )
99 {
100         fstring devicepath;
101         char *ptr;
102         REGVAL_CTR *values;
103         REGISTRY_VALUE *val;
104
105         rpcstr_pull(devicepath, q_u->devicepath.buffer, sizeof(devicepath), q_u->devicepath.uni_str_len*2, 0);
106
107         switch( q_u->property ) {
108         case DEV_REGPROP_DESC:
109                 /* just parse the service name from the device path and then 
110                    lookup the display name */
111                 if ( !(ptr = strrchr_m( devicepath, '\\' )) )
112                         return WERR_GENERAL_FAILURE;    
113                 *ptr = '\0';
114                 
115                 if ( !(ptr = strrchr_m( devicepath, '_' )) )
116                         return WERR_GENERAL_FAILURE;    
117                 ptr++;
118                 
119                 if ( !(values = svcctl_fetch_regvalues( ptr, p->pipe_user.nt_user_token )) )
120                         return WERR_GENERAL_FAILURE;    
121                 
122                 if ( !(val = regval_ctr_getvalue( values, "DisplayName" )) ) {
123                         TALLOC_FREE( values );
124                         return WERR_GENERAL_FAILURE;
125                 }
126                 
127                 r_u->unknown1 = 0x1;    /* always 1...tested using a remove device manager connection */
128                 r_u->size = reg_init_regval_buffer( &r_u->value, val );
129                 r_u->needed = r_u->size;
130
131                 TALLOC_FREE(values);
132
133                 break;
134                 
135         default:
136                 r_u->unknown1 = 0x00437c98;
137                 return WERR_CM_NO_SUCH_VALUE;
138         }
139
140         return WERR_OK;
141 }
142
143 /********************************************************************
144 ********************************************************************/
145
146 WERROR _ntsvcs_validate_device_instance( pipes_struct *p, NTSVCS_Q_VALIDATE_DEVICE_INSTANCE *q_u, NTSVCS_R_VALIDATE_DEVICE_INSTANCE *r_u )
147 {
148         /* whatever dude */
149         return WERR_OK;
150 }
151
152 /********************************************************************
153 ********************************************************************/
154
155 WERROR _ntsvcs_get_hw_profile_info( pipes_struct *p, NTSVCS_Q_GET_HW_PROFILE_INFO *q_u, NTSVCS_R_GET_HW_PROFILE_INFO *r_u )
156 {
157         /* steal the incoming buffer */
158
159         r_u->buffer_size = q_u->buffer_size;
160         r_u->buffer = q_u->buffer;
161
162         /* Take the 5th Ammentment */
163
164         return WERR_CM_NO_MORE_HW_PROFILES;
165 }
166
167 /********************************************************************
168 ********************************************************************/
169
170 WERROR _ntsvcs_hw_profile_flags( pipes_struct *p, NTSVCS_Q_HW_PROFILE_FLAGS *q_u, NTSVCS_R_HW_PROFILE_FLAGS *r_u )
171 {       
172         /* just nod your head */
173         
174         return WERR_OK;
175 }
176