The FSF has moved around a lot. This fixes their Mass Ave address.
[metze/old/v3-2-winbind-ndr.git] / source / services / services_db.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  Service Control API Implementation
4  * 
5  *  Copyright (C) Marcin Krzysztof Porwit         2005.
6  *  Largely Rewritten by:
7  *  Copyright (C) Gerald (Jerry) Carter           2005.
8  *  
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 3 of the License, or
12  *  (at your option) any later version.
13  *  
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *  
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #include "includes.h"
24
25 struct rcinit_file_information {
26         char *description;
27 };
28
29 struct service_display_info {
30         const char *servicename;
31         const char *daemon;
32         const char *dispname;
33         const char *description;
34 };
35
36 struct service_display_info builtin_svcs[] = {  
37   { "Spooler",        "smbd",   "Print Spooler", "Internal service for spooling files to print devices" },
38   { "NETLOGON",       "smbd",   "Net Logon", "File service providing access to policy and profile data (not remotely manageable)" },
39   { "RemoteRegistry", "smbd",   "Remote Registry Service", "Internal service providing remote access to "
40                                 "the Samba registry" },
41   { "WINS",           "nmbd",   "Windows Internet Name Service (WINS)", "Internal service providing a "
42                                 "NetBIOS point-to-point name server (not remotely manageable)" },
43   { NULL, NULL, NULL, NULL }
44 };
45
46 struct service_display_info common_unix_svcs[] = {  
47   { "cups",          NULL, "Common Unix Printing System","Provides unified printing support for all operating systems" },
48   { "postfix",       NULL, "Internet Mail Service",     "Provides support for sending and receiving electonic mail" },
49   { "sendmail",      NULL, "Internet Mail Service",     "Provides support for sending and receiving electonic mail" },
50   { "portmap",       NULL, "TCP Port to RPC PortMapper",NULL },
51   { "xinetd",        NULL, "Internet Meta-Daemon",      NULL },
52   { "inet",          NULL, "Internet Meta-Daemon",      NULL },
53   { "xntpd",         NULL, "Network Time Service",      NULL },
54   { "ntpd",          NULL, "Network Time Service",      NULL },
55   { "lpd",           NULL, "BSD Print Spooler",         NULL },
56   { "nfsserver",     NULL, "Network File Service",      NULL },
57   { "cron",          NULL, "Scheduling Service",        NULL },
58   { "at",            NULL, "Scheduling Service",        NULL },
59   { "nscd",          NULL, "Name Service Cache Daemon", NULL },
60   { "slapd",         NULL, "LDAP Directory Service",    NULL },
61   { "ldap",          NULL, "LDAP DIrectory Service",    NULL },
62   { "ypbind",        NULL, "NIS Directory Service",     NULL },
63   { "courier-imap",  NULL, "IMAP4 Mail Service",        NULL },
64   { "courier-pop3",  NULL, "POP3 Mail Service",         NULL },
65   { "named",         NULL, "Domain Name Service",       NULL },
66   { "bind",          NULL, "Domain Name Service",       NULL },
67   { "httpd",         NULL, "HTTP Server",               NULL },
68   { "apache",        NULL, "HTTP Server",               "Provides s highly scalable and flexible web server "
69                                                         "capable of implementing various protocols incluing "
70                                                         "but not limited to HTTP" },
71   { "autofs",        NULL, "Automounter",               NULL },
72   { "squid",         NULL, "Web Cache Proxy ",          NULL },
73   { "perfcountd",    NULL, "Performance Monitoring Daemon", NULL },
74   { "pgsql",         NULL, "PgSQL Database Server",     "Provides service for SQL database from Postgresql.org" },
75   { "arpwatch",      NULL, "ARP Tables watcher",        "Provides service for monitoring ARP tables for changes" },
76   { "dhcpd",         NULL, "DHCP Server",               "Provides service for dynamic host configuration and IP assignment" },
77   { "nwserv",        NULL, "NetWare Server Emulator",   "Provides service for emulating Novell NetWare 3.12 server" },
78   { "proftpd",       NULL, "Professional FTP Server",   "Provides high configurable service for FTP connection and "
79                                                         "file transferring" },
80   { "ssh2",          NULL, "SSH Secure Shell",          "Provides service for secure connection for remote administration" },
81   { "sshd",          NULL, "SSH Secure Shell",          "Provides service for secure connection for remote administration" },
82   { NULL, NULL, NULL, NULL }
83 };
84
85
86 /********************************************************************
87 ********************************************************************/
88
89 static SEC_DESC* construct_service_sd( TALLOC_CTX *ctx )
90 {
91         SEC_ACE ace[4]; 
92         SEC_ACCESS mask;
93         size_t i = 0;
94         SEC_DESC *sd;
95         SEC_ACL *acl;
96         size_t sd_size;
97         
98         /* basic access for Everyone */
99         
100         init_sec_access(&mask, SERVICE_READ_ACCESS );
101         init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
102                 
103         init_sec_access(&mask,SERVICE_EXECUTE_ACCESS );
104         init_sec_ace(&ace[i++], &global_sid_Builtin_Power_Users, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
105         
106         init_sec_access(&mask,SERVICE_ALL_ACCESS );
107         init_sec_ace(&ace[i++], &global_sid_Builtin_Server_Operators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
108         init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
109         
110         /* create the security descriptor */
111         
112         if ( !(acl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) )
113                 return NULL;
114
115         if ( !(sd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, acl, &sd_size)) )
116                 return NULL;
117
118         return sd;
119 }
120
121 /********************************************************************
122  This is where we do the dirty work of filling in things like the
123  Display name, Description, etc...
124 ********************************************************************/
125
126 static char *get_common_service_dispname( const char *servicename )
127 {
128         static fstring dispname;
129         int i;
130         
131         for ( i=0; common_unix_svcs[i].servicename; i++ ) {
132                 if ( strequal( servicename, common_unix_svcs[i].servicename ) ) {
133                         fstr_sprintf( dispname, "%s (%s)", 
134                                 common_unix_svcs[i].dispname,
135                                 common_unix_svcs[i].servicename );
136                                 
137                         return dispname;
138                 }
139         } 
140         
141         fstrcpy( dispname, servicename );
142         
143         return dispname;
144 }
145
146 /********************************************************************
147 ********************************************************************/
148
149 static char* cleanup_string( const char *string )
150 {
151         static pstring clean;
152         char *begin, *end;
153
154         pstrcpy( clean, string );
155         begin = clean;
156         
157         /* trim any beginning whilespace */
158         
159         while ( isspace(*begin) )
160                 begin++;
161
162         if ( *begin == '\0' )
163                 return NULL;
164                         
165         /* trim any trailing whitespace or carriage returns.
166            Start at the end and move backwards */
167                         
168         end = begin + strlen(begin) - 1;
169                         
170         while ( isspace(*end) || *end=='\n' || *end=='\r' ) {
171                 *end = '\0';
172                 end--;
173         }
174
175         return begin;
176 }
177
178 /********************************************************************
179 ********************************************************************/
180
181 static BOOL read_init_file( const char *servicename, struct rcinit_file_information **service_info )
182 {
183         struct rcinit_file_information *info;
184         pstring filepath, str;
185         XFILE *f;
186         char *p;
187                 
188         if ( !(info = TALLOC_ZERO_P( NULL, struct rcinit_file_information ) ) )
189                 return False;
190         
191         /* attempt the file open */
192                 
193         pstr_sprintf( filepath, "%s/%s/%s", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, servicename );
194         if ( !(f = x_fopen( filepath, O_RDONLY, 0 )) ) {
195                 DEBUG(0,("read_init_file: failed to open [%s]\n", filepath));
196                 TALLOC_FREE(info);
197                 return False;
198         }
199         
200         while ( (x_fgets( str, sizeof(str)-1, f )) != NULL ) {
201                 /* ignore everything that is not a full line 
202                    comment starting with a '#' */
203                    
204                 if ( str[0] != '#' )
205                         continue;
206                 
207                 /* Look for a line like '^#.*Description:' */
208                 
209                 if ( (p = strstr( str, "Description:" )) != NULL ) {
210                         char *desc;
211
212                         p += strlen( "Description:" ) + 1;
213                         if ( !p ) 
214                                 break;
215                                 
216                         if ( (desc = cleanup_string(p)) != NULL )
217                                 info->description = talloc_strdup( info, desc );
218                 }
219         }
220         
221         x_fclose( f );
222         
223         if ( !info->description )
224                 info->description = talloc_strdup( info, "External Unix Service" );
225         
226         *service_info = info;
227         
228         return True;
229 }
230
231 /********************************************************************
232  This is where we do the dirty work of filling in things like the
233  Display name, Description, etc...
234 ********************************************************************/
235
236 static void fill_service_values( const char *name, REGVAL_CTR *values )
237 {
238         UNISTR2 data, dname, ipath, description;
239         uint32 dword;
240         pstring pstr;
241         int i;
242         
243         /* These values are hardcoded in all QueryServiceConfig() replies.
244            I'm just storing them here for cosmetic purposes */
245         
246         dword = SVCCTL_AUTO_START;
247         regval_ctr_addvalue( values, "Start", REG_DWORD, (char*)&dword, sizeof(uint32));
248         
249         dword = SVCCTL_WIN32_OWN_PROC;
250         regval_ctr_addvalue( values, "Type", REG_DWORD, (char*)&dword, sizeof(uint32));
251
252         dword = SVCCTL_SVC_ERROR_NORMAL;
253         regval_ctr_addvalue( values, "ErrorControl", REG_DWORD, (char*)&dword, sizeof(uint32));
254         
255         /* everything runs as LocalSystem */
256         
257         init_unistr2( &data, "LocalSystem", UNI_STR_TERMINATE );
258         regval_ctr_addvalue( values, "ObjectName", REG_SZ, (char*)data.buffer, data.uni_str_len*2);
259         
260         /* special considerations for internal services and the DisplayName value */
261         
262         for ( i=0; builtin_svcs[i].servicename; i++ ) {
263                 if ( strequal( name, builtin_svcs[i].servicename ) ) {
264                         pstr_sprintf( pstr, "%s/%s/%s",dyn_LIBDIR, SVCCTL_SCRIPT_DIR, builtin_svcs[i].daemon );
265                         init_unistr2( &ipath, pstr, UNI_STR_TERMINATE );
266                         init_unistr2( &description, builtin_svcs[i].description, UNI_STR_TERMINATE );
267                         init_unistr2( &dname, builtin_svcs[i].dispname, UNI_STR_TERMINATE );
268                         break;
269                 }
270         } 
271         
272         /* default to an external service if we haven't found a match */
273         
274         if ( builtin_svcs[i].servicename == NULL ) {
275                 struct rcinit_file_information *init_info = NULL;
276
277                 pstr_sprintf( pstr, "%s/%s/%s",dyn_LIBDIR, SVCCTL_SCRIPT_DIR, name );
278                 init_unistr2( &ipath, pstr, UNI_STR_TERMINATE );
279                 
280                 /* lookup common unix display names */
281                 init_unistr2( &dname, get_common_service_dispname( name ), UNI_STR_TERMINATE );
282
283                 /* get info from init file itself */            
284                 if ( read_init_file( name, &init_info ) ) {
285                         init_unistr2( &description, init_info->description, UNI_STR_TERMINATE );
286                         TALLOC_FREE( init_info );
287                 }
288                 else {
289                         init_unistr2( &description, "External Unix Service", UNI_STR_TERMINATE );
290                 }
291         }
292         
293         /* add the new values */
294         
295         regval_ctr_addvalue( values, "DisplayName", REG_SZ, (char*)dname.buffer, dname.uni_str_len*2);
296         regval_ctr_addvalue( values, "ImagePath", REG_SZ, (char*)ipath.buffer, ipath.uni_str_len*2);
297         regval_ctr_addvalue( values, "Description", REG_SZ, (char*)description.buffer, description.uni_str_len*2);
298         
299         return;
300 }
301
302 /********************************************************************
303 ********************************************************************/
304
305 static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, 
306                               const char *name )
307 {
308         REGISTRY_KEY *key_service, *key_secdesc;
309         WERROR wresult;
310         pstring path;
311         REGVAL_CTR *values;
312         REGSUBKEY_CTR *svc_subkeys;
313         SEC_DESC *sd;
314         prs_struct ps;
315
316         /* add to the list and create the subkey path */
317
318         regsubkey_ctr_addkey( subkeys, name );
319         store_reg_keys( key_parent, subkeys );
320
321         /* open the new service key */
322
323         pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name );
324         wresult = regkey_open_internal( NULL, &key_service, path,
325                                         get_root_nt_token(), REG_KEY_ALL );
326         if ( !W_ERROR_IS_OK(wresult) ) {
327                 DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", 
328                         path, dos_errstr(wresult)));
329                 return;
330         }
331         
332         /* add the 'Security' key */
333
334         if ( !(svc_subkeys = TALLOC_ZERO_P( key_service, REGSUBKEY_CTR )) ) {
335                 DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
336                 TALLOC_FREE( key_service );
337                 return;
338         }
339         
340         fetch_reg_keys( key_service, svc_subkeys );
341         regsubkey_ctr_addkey( svc_subkeys, "Security" );
342         store_reg_keys( key_service, svc_subkeys );
343
344         /* now for the service values */
345         
346         if ( !(values = TALLOC_ZERO_P( key_service, REGVAL_CTR )) ) {
347                 DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
348                 TALLOC_FREE( key_service );
349                 return;
350         }
351
352         fill_service_values( name, values );
353         store_reg_values( key_service, values );
354
355         /* cleanup the service key*/
356
357         TALLOC_FREE( key_service );
358
359         /* now add the security descriptor */
360
361         pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" );
362         wresult = regkey_open_internal( NULL, &key_secdesc, path,
363                                         get_root_nt_token(), REG_KEY_ALL );
364         if ( !W_ERROR_IS_OK(wresult) ) {
365                 DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", 
366                         path, dos_errstr(wresult)));
367                 TALLOC_FREE( key_secdesc );
368                 return;
369         }
370
371         if ( !(values = TALLOC_ZERO_P( key_secdesc, REGVAL_CTR )) ) {
372                 DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
373                 TALLOC_FREE( key_secdesc );
374                 return;
375         }
376
377         if ( !(sd = construct_service_sd(key_secdesc)) ) {
378                 DEBUG(0,("add_new_svc_name: Failed to create default sec_desc!\n"));
379                 TALLOC_FREE( key_secdesc );
380                 return;
381         }
382         
383         /* stream the printer security descriptor */
384         
385         prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key_secdesc, MARSHALL);
386         
387         if ( sec_io_desc("sec_desc", &sd, &ps, 0 ) ) {
388                 uint32 offset = prs_offset( &ps );
389                 regval_ctr_addvalue( values, "Security", REG_BINARY, prs_data_p(&ps), offset );
390                 store_reg_values( key_secdesc, values );
391         }
392         
393         /* finally cleanup the Security key */
394         
395         prs_mem_free( &ps );
396         TALLOC_FREE( key_secdesc );
397
398         return;
399 }
400
401 /********************************************************************
402 ********************************************************************/
403
404 void svcctl_init_keys( void )
405 {
406         const char **service_list = lp_svcctl_list();
407         int i;
408         REGSUBKEY_CTR *subkeys;
409         REGISTRY_KEY *key = NULL;
410         WERROR wresult;
411         
412         /* bad mojo here if the lookup failed.  Should not happen */
413         
414         wresult = regkey_open_internal( NULL, &key, KEY_SERVICES,
415                                         get_root_nt_token(), REG_KEY_ALL );
416
417         if ( !W_ERROR_IS_OK(wresult) ) {
418                 DEBUG(0,("init_services_keys: key lookup failed! (%s)\n", 
419                         dos_errstr(wresult)));
420                 return;
421         }
422         
423         /* lookup the available subkeys */      
424         
425         if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) {
426                 DEBUG(0,("init_services_keys: talloc() failed!\n"));
427                 TALLOC_FREE( key );
428                 return;
429         }
430         
431         fetch_reg_keys( key, subkeys );
432         
433         /* the builting services exist */
434         
435         for ( i=0; builtin_svcs[i].servicename; i++ )
436                 add_new_svc_name( key, subkeys, builtin_svcs[i].servicename );
437                 
438         for ( i=0; service_list && service_list[i]; i++ ) {
439         
440                 /* only add new services */
441                 if ( regsubkey_ctr_key_exists( subkeys, service_list[i] ) )
442                         continue;
443
444                 /* Add the new service key and initialize the appropriate values */
445
446                 add_new_svc_name( key, subkeys, service_list[i] );
447         }
448
449         TALLOC_FREE( key );
450
451         /* initialize the control hooks */
452
453         init_service_op_table();
454
455         return;
456 }
457
458 /********************************************************************
459  This is where we do the dirty work of filling in things like the
460  Display name, Description, etc...Always return a default secdesc 
461  in case of any failure.
462 ********************************************************************/
463
464 SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token )
465 {
466         REGISTRY_KEY *key;
467         prs_struct ps;
468         REGVAL_CTR *values;
469         REGISTRY_VALUE *val;
470         SEC_DESC *sd = NULL;
471         SEC_DESC *ret_sd = NULL;
472         pstring path;
473         WERROR wresult;
474         
475         /* now add the security descriptor */
476
477         pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" );
478         wresult = regkey_open_internal( NULL, &key, path, token,
479                                         REG_KEY_ALL );
480         if ( !W_ERROR_IS_OK(wresult) ) {
481                 DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", 
482                         path, dos_errstr(wresult)));
483                 return NULL;
484         }
485
486         if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
487                 DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
488                 TALLOC_FREE( key );
489                 return NULL;
490         }
491
492         fetch_reg_values( key, values );
493         
494         if ( !(val = regval_ctr_getvalue( values, "Security" )) ) {
495                 DEBUG(6,("svcctl_get_secdesc: constructing default secdesc for service [%s]\n", 
496                         name));
497                 TALLOC_FREE( key );
498                 return construct_service_sd( ctx );
499         }
500         
501
502         /* stream the printer security descriptor */
503         
504         prs_init( &ps, 0, key, UNMARSHALL);
505         prs_give_memory( &ps, (char *)regval_data_p(val), regval_size(val), False );
506         
507         if ( !sec_io_desc("sec_desc", &sd, &ps, 0 ) ) {
508                 TALLOC_FREE( key );
509                 return construct_service_sd( ctx );
510         }
511         
512         ret_sd = dup_sec_desc( ctx, sd );
513         
514         /* finally cleanup the Security key */
515         
516         prs_mem_free( &ps );
517         TALLOC_FREE( key );
518
519         return ret_sd;
520 }
521
522 /********************************************************************
523  Wrapper to make storing a Service sd easier
524 ********************************************************************/
525
526 BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, NT_USER_TOKEN *token )
527 {
528         REGISTRY_KEY *key;
529         WERROR wresult;
530         pstring path;
531         REGVAL_CTR *values;
532         prs_struct ps;
533         BOOL ret = False;
534         
535         /* now add the security descriptor */
536
537         pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" );
538         wresult = regkey_open_internal( NULL, &key, path, token,
539                                         REG_KEY_ALL );
540         if ( !W_ERROR_IS_OK(wresult) ) {
541                 DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", 
542                         path, dos_errstr(wresult)));
543                 return False;
544         }
545
546         if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
547                 DEBUG(0,("add_new_svc_name: talloc() failed!\n"));
548                 TALLOC_FREE( key );
549                 return False;
550         }
551         
552         /* stream the printer security descriptor */
553         
554         prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key, MARSHALL);
555         
556         if ( sec_io_desc("sec_desc", &sec_desc, &ps, 0 ) ) {
557                 uint32 offset = prs_offset( &ps );
558                 regval_ctr_addvalue( values, "Security", REG_BINARY, prs_data_p(&ps), offset );
559                 ret = store_reg_values( key, values );
560         }
561         
562         /* cleanup */
563         
564         prs_mem_free( &ps );
565         TALLOC_FREE( key);
566
567         return ret;
568 }
569
570 /********************************************************************
571 ********************************************************************/
572
573 char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token )
574 {
575         static fstring display_name;
576         REGISTRY_KEY *key;
577         REGVAL_CTR *values;
578         REGISTRY_VALUE *val;
579         pstring path;
580         WERROR wresult;
581         
582         /* now add the security descriptor */
583
584         pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name );
585         wresult = regkey_open_internal( NULL, &key, path, token,
586                                         REG_KEY_READ );
587         if ( !W_ERROR_IS_OK(wresult) ) {
588                 DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", 
589                         path, dos_errstr(wresult)));
590                 goto fail;
591         }
592
593         if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
594                 DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n"));
595                 TALLOC_FREE( key );
596                 goto fail;
597         }
598
599         fetch_reg_values( key, values );
600         
601         if ( !(val = regval_ctr_getvalue( values, "DisplayName" )) )
602                 goto fail;
603
604         rpcstr_pull( display_name, regval_data_p(val), sizeof(display_name), regval_size(val), 0 );
605
606         TALLOC_FREE( key );
607         
608         return display_name;
609
610 fail:
611         /* default to returning the service name */
612         TALLOC_FREE( key );
613         fstrcpy( display_name, name );
614         return display_name;
615 }
616
617 /********************************************************************
618 ********************************************************************/
619
620 char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token )
621 {
622         static fstring description;
623         REGISTRY_KEY *key;
624         REGVAL_CTR *values;
625         REGISTRY_VALUE *val;
626         pstring path;
627         WERROR wresult;
628         
629         /* now add the security descriptor */
630
631         pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name );
632         wresult = regkey_open_internal( NULL, &key, path, token,
633                                         REG_KEY_READ );
634         if ( !W_ERROR_IS_OK(wresult) ) {
635                 DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", 
636                         path, dos_errstr(wresult)));
637                 return NULL;
638         }
639
640         if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) {
641                 DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n"));
642                 TALLOC_FREE( key );
643                 return NULL;
644         }
645
646         fetch_reg_values( key, values );
647         
648         if ( !(val = regval_ctr_getvalue( values, "Description" )) )
649                 fstrcpy( description, "Unix Service");
650         else
651                 rpcstr_pull( description, regval_data_p(val), sizeof(description), regval_size(val), 0 );
652
653         TALLOC_FREE( key );
654         
655         return description;
656 }
657
658
659 /********************************************************************
660 ********************************************************************/
661
662 REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token )
663 {
664         REGISTRY_KEY *key;
665         REGVAL_CTR *values;
666         pstring path;
667         WERROR wresult;
668         
669         /* now add the security descriptor */
670
671         pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name );
672         wresult = regkey_open_internal( NULL, &key, path, token,
673                                         REG_KEY_READ );
674         if ( !W_ERROR_IS_OK(wresult) ) {
675                 DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n", 
676                         path, dos_errstr(wresult)));
677                 return NULL;
678         }
679
680         if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) {
681                 DEBUG(0,("svcctl_fetch_regvalues: talloc() failed!\n"));
682                 TALLOC_FREE( key );
683                 return NULL;
684         }
685         
686         fetch_reg_values( key, values );
687
688         TALLOC_FREE( key );
689         
690         return values;
691 }
692