r10656: BIG merge from trunk. Features not copied over
[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 2 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, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include "includes.h"
23
24 #undef DBGC_CLASS
25 #define DBGC_CLASS DBGC_RPC_SRV
26
27 /********************************************************************
28 ********************************************************************/
29
30 static char* get_device_path( const char *device )
31 {
32         static pstring path;
33
34         pstr_sprintf( path, "ROOT\\Legacy_%s\\0000", device );
35
36         return path;
37 }
38
39 /********************************************************************
40 ********************************************************************/
41
42 WERROR _ntsvcs_get_version( pipes_struct *p, NTSVCS_Q_GET_VERSION *q_u, NTSVCS_R_GET_VERSION *r_u )
43 {
44         r_u->version = 0x00000400;      /* no idea what this means */
45                 
46         return WERR_OK;
47 }
48
49 /********************************************************************
50 ********************************************************************/
51
52 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 )
53 {
54         fstring device;
55         const char *devicepath;
56
57         if ( !q_u->devicename )
58                 return WERR_ACCESS_DENIED;
59
60         rpcstr_pull(device, q_u->devicename->buffer, sizeof(device), q_u->devicename->uni_str_len*2, 0);
61         devicepath = get_device_path( device );
62
63         r_u->size = strlen(devicepath) + 2;
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         const 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         devicepath = get_device_path( device );
82
83         /* From the packet traces I've see, I think this really should be an array
84            of UNISTR2's.  But I've never seen more than one string in spite of the 
85            fact that the string in double NULL terminated.  -- jerry */
86
87         init_unistr2( &r_u->devicepath, devicepath, UNI_STR_TERMINATE );
88         r_u->needed = r_u->devicepath.uni_str_len;
89
90         return WERR_OK;
91 }
92
93 /********************************************************************
94 ********************************************************************/
95
96 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 )
97 {
98         fstring devicepath;
99         char *ptr;
100         REGVAL_CTR *values;
101         REGISTRY_VALUE *val;
102
103         rpcstr_pull(devicepath, q_u->devicepath.buffer, sizeof(devicepath), q_u->devicepath.uni_str_len*2, 0);
104
105         switch( q_u->property ) {
106         case DEV_REGPROP_DESC:
107                 /* just parse the service name from the device path and then 
108                    lookup the display name */
109                 if ( !(ptr = strrchr_m( devicepath, '\\' )) )
110                         return WERR_GENERAL_FAILURE;    
111                 *ptr = '\0';
112                 
113                 if ( !(ptr = strrchr_m( devicepath, '_' )) )
114                         return WERR_GENERAL_FAILURE;    
115                 ptr++;
116                 
117                 if ( !(values = svcctl_fetch_regvalues( ptr, p->pipe_user.nt_user_token )) )
118                         return WERR_GENERAL_FAILURE;    
119                 
120                 if ( !(val = regval_ctr_getvalue( values, "DisplayName" )) ) {
121                         TALLOC_FREE( values );
122                         return WERR_GENERAL_FAILURE;
123                 }
124                 
125                 r_u->unknown1 = 0x1;    /* always 1...tested using a remove device manager connection */
126                 r_u->size = reg_init_regval_buffer( &r_u->value, val );
127                 r_u->needed = r_u->size;
128
129                 TALLOC_FREE(values);
130
131                 break;
132                 
133         default:
134                 r_u->unknown1 = 0x00437c98;
135                 return WERR_CM_NO_SUCH_VALUE;
136         }
137
138         return WERR_OK;
139 }
140
141 /********************************************************************
142 ********************************************************************/
143
144 WERROR _ntsvcs_validate_device_instance( pipes_struct *p, NTSVCS_Q_VALIDATE_DEVICE_INSTANCE *q_u, NTSVCS_R_VALIDATE_DEVICE_INSTANCE *r_u )
145 {
146         /* whatever dude */
147         return WERR_OK;
148 }
149
150 /********************************************************************
151 ********************************************************************/
152
153 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 )
154 {
155         /* steal the incoming buffer */
156
157         r_u->buffer_size = q_u->buffer_size;
158         r_u->buffer = q_u->buffer;
159
160         /* Take the 5th Ammentment */
161
162         return WERR_CM_NO_MORE_HW_PROFILES;
163 }
164
165 /********************************************************************
166 ********************************************************************/
167
168 WERROR _ntsvcs_hw_profile_flags( pipes_struct *p, NTSVCS_Q_HW_PROFILE_FLAGS *q_u, NTSVCS_R_HW_PROFILE_FLAGS *r_u )
169 {       
170         /* just nod your head */
171         
172         return WERR_OK;
173 }
174