From 2851e43e4881485b0af418975eca8f01ab27ca3b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 15 Jun 2005 00:54:43 +0000 Subject: r7595: start trying to split out the svcctl functions into separate files for better maintenance; add SERVICE_CONTROL_OPS for spoolss service (This used to be commit 2b0ea30a1a3aebaabd5d328de50e6ad2ef18d45d) --- source3/services/services_db.c | 573 +++++++++++++++++++++++++++++++++++++++++ source3/services/svc_rcinit.c | 204 +++++++++++++++ source3/services/svc_spoolss.c | 58 +++++ 3 files changed, 835 insertions(+) create mode 100644 source3/services/services_db.c create mode 100644 source3/services/svc_rcinit.c create mode 100644 source3/services/svc_spoolss.c (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c new file mode 100644 index 0000000000..df74387959 --- /dev/null +++ b/source3/services/services_db.c @@ -0,0 +1,573 @@ +/* + * Unix SMB/CIFS implementation. + * Service Control API Implementation + * Copyright (C) Gerald Carter 2005. + * Copyright (C) Marcin Krzysztof Porwit 2005. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* backend database routines for services.tdb */ + +#define SERVICEDB_VERSION_V1 1 /* Will there be more? */ +#define INTERNAL_SERVICES_LIST "NETLOGON Spooler" + +/* */ +/* scripts will execute from the following libdir, if they are in the enable svcctl= */ +/* these should likely be symbolic links. Note that information about them will be extracted from the files themselves */ +/* using the LSB standard keynames for various information */ + +#define SCVCTL_DATABASE_VERSION_V1 1 +static TDB_CONTEXT *service_tdb; /* used for services tdb file */ + +/* there are two types of services -- internal, and external. + Internal services are "built-in" to samba -- there may be + functions that exist to provide the control and enumeration + functions. There certainly is information returned to be + displayed in the typical management console. + + External services are those that can be specified in the smb.conf + file -- and they conform to the LSB specification as to having + particular keywords in the scripts. Note that these "scripts" are + located in the lib directory, and are likely links to LSB-compliant + init.d scripts, such as those that might come with Suse. Note + that the spec is located http://www.linuxbase.org/spec/ */ + + + +/* Expand this to include what can and can't be done + with a particular internal service. Expand as necessary + to add other infromation like what can be controlled, + etc. */ + +typedef struct Internal_service_struct +{ + const char *filename; /* internal name "index" */ + const char *displayname; + const char *description; + const uint32 statustype; + void *status_fn; + void *control_fn; +} Internal_service_description; + + +static const Internal_service_description ISD[] = { + { "NETLOGON", "Net Logon", "Provides logon and authentication service to the network", 0x110, NULL, NULL}, + { "Spooler", "Spooler", "Printing Services", 0x0020, NULL, NULL}, + { NULL, NULL, NULL, 0, NULL, NULL} +}; + + +/******************************************************************** + allocate an array of external services and return them. Null return + is okay, make sure &added is also zero! +********************************************************************/ + +int num_external_services(void) +{ + int num_services; + char **svc_list; + pstring keystring, external_services_string; + TDB_DATA key_data; + + + if (!service_tdb) { + DEBUG(8,("enum_external_services: service database is not open!!!\n")); + num_services = 0; + } else { + pstrcpy(keystring,"EXTERNAL_SERVICES"); + tdb_lock_bystring(service_tdb, keystring, 0); + key_data = tdb_fetch_bystring(service_tdb, keystring); + + if ((key_data.dptr != NULL) && (key_data.dsize != 0)) { + strncpy(external_services_string,key_data.dptr,key_data.dsize); + external_services_string[key_data.dsize] = 0; + DEBUG(8,("enum_external_services: services list is %s, size is %d\n",external_services_string,key_data.dsize)); + } + tdb_unlock_bystring(service_tdb, keystring); + } + svc_list = str_list_make(external_services_string,NULL); + + num_services = str_list_count( (const char **)svc_list); + + return num_services; +} + + + +/******************************************************************** + Gather information on the "external services". These are services + listed in the smb.conf file, and found to exist through checks in + this code. Note that added will be incremented on the basis of the + number of services added. svc_ptr should have enough memory allocated + to accommodate all of the services that exist. + + Typically num_external_services is used to "size" the amount of + memory allocated, but does little/no work. + + enum_external_services() actually examines each of the specified + external services, populates the memory structures, and returns. + + ** note that 'added' may end up with less than the number of services + found in _num_external_services, such as the case when a service is + called out, but the actual service doesn't exist or the file can't be + read for the service information. +********************************************************************/ + +WERROR enum_external_services(TALLOC_CTX *tcx,ENUM_SERVICES_STATUS **svc_ptr, int existing_services,int *added) +{ + /* *svc_ptr must have pre-allocated memory */ + int num_services = 0; + int i = 0; + ENUM_SERVICES_STATUS *services=NULL; + char **svc_list,**svcname; + pstring command, keystring, external_services_string; + int ret; + int fd = -1; + Service_info *si; + TDB_DATA key_data; + + *added = num_services; + + if (!service_tdb) { + DEBUG(8,("enum_external_services: service database is not open!!!\n")); + } else { + pstrcpy(keystring,"EXTERNAL_SERVICES"); + tdb_lock_bystring(service_tdb, keystring, 0); + key_data = tdb_fetch_bystring(service_tdb, keystring); + if ((key_data.dptr != NULL) && (key_data.dsize != 0)) { + strncpy(external_services_string,key_data.dptr,key_data.dsize); + external_services_string[key_data.dsize] = 0; + DEBUG(8,("enum_external_services: services list is %s, size is %d\n",external_services_string,key_data.dsize)); + } + tdb_unlock_bystring(service_tdb, keystring); + } + svc_list = str_list_make(external_services_string,NULL); + + num_services = str_list_count( (const char **)svc_list); + + if (0 == num_services) { + DEBUG(8,("enum_external_services: there are no external services\n")); + *added = num_services; + return WERR_OK; + } + DEBUG(8,("enum_external_services: there are [%d] external services\n",num_services)); + si=TALLOC_ARRAY( tcx, Service_info, 1 ); + if (si == NULL) { + DEBUG(8,("enum_external_services: Failed to alloc si\n")); + return WERR_NOMEM; + } + +#if 0 +/* *svc_ptr has the pointer to the array if there is one already. NULL if not. */ + if ((existing_services>0) && svc_ptr && *svc_ptr) { /* reallocate vs. allocate */ + DEBUG(8,("enum_external_services: REALLOCing %x to %d services\n", *svc_ptr, existing_services+num_services)); + + services=TALLOC_REALLOC_ARRAY(tcx,*svc_ptr,ENUM_SERVICES_STATUS,existing_services+num_services); + DEBUG(8,("enum_external_services: REALLOCed to %x services\n", services)); + + if (!services) return WERR_NOMEM; + *svc_ptr = services; + } else { + if ( !(services = TALLOC_ARRAY( tcx, ENUM_SERVICES_STATUS, num_services )) ) + return WERR_NOMEM; + } +#endif + + if (!svc_ptr || !(*svc_ptr)) + return WERR_NOMEM; + services = *svc_ptr; + if (existing_services > 0) { + i+=existing_services; + } + + svcname = svc_list; + DEBUG(8,("enum_external_services: enumerating %d external services starting at index %d\n", num_services,existing_services)); + + while (*svcname) { + DEBUG(10,("enum_external_services: Reading information on service %s, index %d\n",*svcname,i)); + /* get_LSB_data(*svcname,si); */ + if (!get_service_info(service_tdb,*svcname, si)) { + DEBUG(1,("enum_external_services: CAN'T FIND INFO FOR SERVICE %s in the services DB\n",*svcname)); + } + + if ((si->filename == NULL) || (*si->filename == 0)) { + init_unistr(&services[i].servicename, *svcname ); + } else { + init_unistr( &services[i].servicename, si->filename ); + /* init_unistr( &services[i].servicename, si->servicename ); */ + } + + if ((si->provides == NULL) || (*si->provides == 0)) { + init_unistr(&services[i].displayname, *svcname ); + } else { + init_unistr( &services[i].displayname, si->provides ); + } + + /* TODO - we could keep the following info in the DB, too... */ + + DEBUG(8,("enum_external_services: Service name [%s] displayname [%s]\n", + si->filename, si->provides)); + services[i].status.type = SVCCTL_WIN32_OWN_PROC; + services[i].status.win32_exit_code = 0x0; + services[i].status.service_exit_code = 0x0; + services[i].status.check_point = 0x0; + services[i].status.wait_hint = 0x0; + + /* TODO - do callout here to get the status */ + + memset(command, 0, sizeof(command)); + slprintf(command, sizeof(command)-1, "%s%s%s %s", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, *svcname, "status"); + + DEBUG(10, ("enum_external_services: status command is [%s]\n", command)); + + /* TODO - wrap in privilege check */ + + ret = smbrun(command, &fd); + DEBUGADD(10, ("returned [%d]\n", ret)); + close(fd); + if(ret != 0) + DEBUG(10, ("enum_external_services: Command returned [%d]\n", ret)); + services[i].status.state = SVCCTL_STOPPED; + if (ret == 0) { + services[i].status.state = SVCCTL_RUNNING; + services[i].status.controls_accepted = SVCCTL_CONTROL_SHUTDOWN | SVCCTL_CONTROL_STOP; + } else { + services[i].status.state = SVCCTL_STOPPED; + services[i].status.controls_accepted = 0; + } + svcname++; + i++; + } + + DEBUG(10,("enum_external_services: Read services %d\n",num_services)); + *added = num_services; + + return WERR_OK; +} + +/******************************************************************** +********************************************************************/ + +int num_internal_services(void) +{ + int num_services; + char **svc_list; + pstring keystring, internal_services_string; + TDB_DATA key_data; + + if (!service_tdb) { + DEBUG(8,("enum_internal_services: service database is not open!!!\n")); + num_services = 0; + } else { + pstrcpy(keystring,"INTERNAL_SERVICES"); + tdb_lock_bystring(service_tdb, keystring, 0); + key_data = tdb_fetch_bystring(service_tdb, keystring); + + if ((key_data.dptr != NULL) && (key_data.dsize != 0)) { + strncpy(internal_services_string,key_data.dptr,key_data.dsize); + internal_services_string[key_data.dsize] = 0; + DEBUG(8,("enum_internal_services: services list is %s, size is %d\n",internal_services_string,key_data.dsize)); + } + tdb_unlock_bystring(service_tdb, keystring); + } + svc_list = str_list_make(internal_services_string,NULL); + + num_services = str_list_count( (const char **)svc_list); + + return num_services; +} + +#if 0 +/********************************************************************* + given a service nice name, find the underlying service name +*********************************************************************/ + +static BOOL convert_service_displayname(TDB_CONTEXT *stdb,pstring service_nicename, pstring servicename,int szsvcname) +{ + pstring keystring; + TDB_DATA key_data; + + if ((stdb == NULL) || (service_nicename==NULL) || (servicename == NULL)) + return False; + + pstr_sprintf(keystring,"SERVICE_NICENAME/%s", servicename); + + DEBUG(5, ("convert_service_displayname: Looking for service name [%s], key [%s]\n", + service_nicename, keystring)); + + key_data = tdb_fetch_bystring(stdb,keystring); + + if (key_data.dsize == 0) { + DEBUG(5, ("convert_service_displayname: [%s] Not found, tried key [%s]\n",service_nicename,keystring)); + return False; + } + + strncpy(servicename,key_data.dptr,szsvcname); + servicename[(key_data.dsize > szsvcname ? szsvcname : key_data.dsize)] = 0; + DEBUG(5, ("convert_service_displayname: Found service name [%s], name is [%s]\n", + service_nicename,servicename)); + + return True; +} +#endif + +/******************************************************************************* + Get the INTERNAL services information for the given service name. +*******************************************************************************/ + +static BOOL get_internal_service_data(const Internal_service_description *isd, Service_info *si) +{ + ZERO_STRUCTP( si ); +#if 0 + + pstrcpy( si->servicename, isd->displayname); + pstrcpy( si->servicetype, "INTERNAL"); + pstrcpy( si->filename, isd->filename); + pstrcpy( si->provides, isd->displayname); + pstrcpy( si->description, isd->description); + pstrcpy( si->shortdescription, isd->description); +#endif + + return True; +} + +/******************************************************************** +********************************************************************/ + +BOOL get_service_info(TDB_CONTEXT *stdb,char *service_name, Service_info *si) +{ + + pstring keystring; + TDB_DATA key_data; + + if ((stdb == NULL) || (si == NULL) || (service_name==NULL) || (*service_name == 0)) + return False; + + /* TODO - error handling -- what if the service isn't in the DB? */ + + pstr_sprintf(keystring,"SERVICE/%s/TYPE", service_name); + key_data = tdb_fetch_bystring(stdb,keystring); + strncpy(si->servicetype,key_data.dptr,key_data.dsize); + si->servicetype[key_data.dsize] = 0; + + /* crude check to see if the service exists... */ + DEBUG(3,("Size of the TYPE field is %d\n",key_data.dsize)); + if (key_data.dsize == 0) + return False; + + pstr_sprintf(keystring,"SERVICE/%s/FILENAME", service_name); + key_data = tdb_fetch_bystring(stdb,keystring); + strncpy(si->filename,key_data.dptr,key_data.dsize); + si->filename[key_data.dsize] = 0; + + pstr_sprintf(keystring,"SERVICE/%s/PROVIDES", service_name); + key_data = tdb_fetch_bystring(stdb,keystring); + strncpy(si->provides,key_data.dptr,key_data.dsize); + si->provides[key_data.dsize] = 0; + strncpy(si->servicename,key_data.dptr,key_data.dsize); + si->servicename[key_data.dsize] = 0; + + + pstr_sprintf(keystring,"SERVICE/%s/DEPENDENCIES", service_name); + key_data = tdb_fetch_bystring(stdb,keystring); + strncpy(si->dependencies,key_data.dptr,key_data.dsize); + si->dependencies[key_data.dsize] = 0; + + pstr_sprintf(keystring,"SERVICE/%s/SHOULDSTART", service_name); + key_data = tdb_fetch_bystring(stdb,keystring); + strncpy(si->shouldstart,key_data.dptr,key_data.dsize); + si->shouldstart[key_data.dsize] = 0; + + pstr_sprintf(keystring,"SERVICE/%s/SHOULD_STOP", service_name); + key_data = tdb_fetch_bystring(stdb,keystring); + strncpy(si->shouldstop,key_data.dptr,key_data.dsize); + si->shouldstop[key_data.dsize] = 0; + + pstr_sprintf(keystring,"SERVICE/%s/REQUIREDSTART", service_name); + key_data = tdb_fetch_bystring(stdb,keystring); + strncpy(si->requiredstart,key_data.dptr,key_data.dsize); + si->requiredstart[key_data.dsize] = 0; + + pstr_sprintf(keystring,"SERVICE/%s/REQUIREDSTOP", service_name); + key_data = tdb_fetch_bystring(stdb,keystring); + strncpy(si->requiredstop,key_data.dptr,key_data.dsize); + si->requiredstop[key_data.dsize] = 0; + + pstr_sprintf(keystring,"SERVICE/%s/DESCRIPTION", service_name); + key_data = tdb_fetch_bystring(stdb,keystring); + strncpy(si->description,key_data.dptr,key_data.dsize); + si->description[key_data.dsize] = 0; + + pstr_sprintf(keystring,"SERVICE/%s/SHORTDESC", service_name); + key_data = tdb_fetch_bystring(stdb,keystring); + strncpy(si->shortdescription,key_data.dptr,key_data.dsize); + si->shortdescription[key_data.dsize] = 0; + + return True; +} + +/********************************************************************* +*********************************************************************/ + +BOOL store_service_info(TDB_CONTEXT *stdb,char *service_name, Service_info *si) +{ + pstring keystring; + + /* Note -- when we write to the tdb, we "index" on the filename + field, not the nice name. when a service is "opened", it is + opened by the nice (SERVICENAME) name, not the file name. + So there needs to be a mapping from nice name back to the file name. */ + + if ((stdb == NULL) || (si == NULL) || (service_name==NULL) || (*service_name == 0)) + return False; + + + /* Store the nicename */ + + pstr_sprintf(keystring,"SERVICE_NICENAME/%s", si->servicename); + tdb_store_bystring(stdb,keystring,string_tdb_data(service_name),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/TYPE", service_name); + tdb_store_bystring(stdb,keystring,string_tdb_data(si->servicetype),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/FILENAME", service_name); + tdb_store_bystring(stdb,keystring,string_tdb_data(si->filename),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/PROVIDES", service_name); + tdb_store_bystring(stdb,keystring,string_tdb_data(si->provides),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/SERVICENAME", service_name); + tdb_store_bystring(stdb,keystring,string_tdb_data(si->servicename),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/DEPENDENCIES", service_name); + tdb_store_bystring(stdb,keystring,string_tdb_data(si->dependencies),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/SHOULDSTART", service_name); + tdb_store_bystring(stdb,keystring,string_tdb_data(si->shouldstart),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/SHOULDSTOP", service_name); + tdb_store_bystring(stdb,keystring,string_tdb_data(si->shouldstop),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/REQUIREDSTART", service_name); + tdb_store_bystring(stdb,keystring,string_tdb_data(si->requiredstart),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/REQUIREDSTOP", service_name); + tdb_store_bystring(stdb,keystring,string_tdb_data(si->requiredstop),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/DESCRIPTION", service_name); + tdb_store_bystring(stdb,keystring,string_tdb_data(si->description),TDB_REPLACE); + + pstr_sprintf(keystring,"SERVICE/%s/SHORTDESC", service_name); + tdb_lock_bystring(stdb, keystring, 0); + if (si->shortdescription && *si->shortdescription) + tdb_store_bystring(stdb,keystring,string_tdb_data(si->shortdescription),TDB_REPLACE); + else + tdb_store_bystring(stdb,keystring,string_tdb_data(si->description),TDB_REPLACE); + + return True; +} + +/**************************************************************************** + Create/Open the service control manager tdb. This code a clone of init_group_mapping. +****************************************************************************/ + +BOOL init_svcctl_db(void) +{ + const char *vstring = "INFO/version"; + uint32 vers_id; + char **svc_list; + char **svcname; + pstring keystring; + pstring external_service_list; + pstring internal_service_list; + Service_info si; + const Internal_service_description *isd_ptr; + /* svc_list = str_list_make( "etc/init.d/skeleton etc/init.d/syslog", NULL ); */ + svc_list=(char **)lp_enable_svcctl(); + + if (service_tdb) + return True; + + pstrcpy(external_service_list,""); + + service_tdb = tdb_open_log(lock_path("services.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600); + if (!service_tdb) { + DEBUG(0,("Failed to open service db\n")); + service_tdb = tdb_open_log(lock_path("services.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); + if (!service_tdb) return False; + DEBUG(0,("Created new services db\n")); + } + + if ((-1 == tdb_fetch_uint32(service_tdb, vstring,&vers_id)) || (vers_id != SERVICEDB_VERSION_V1)) { + /* wrong version of DB, or db was just created */ + tdb_traverse(service_tdb, tdb_traverse_delete_fn, NULL); + tdb_store_uint32(service_tdb, vstring, SERVICEDB_VERSION_V1); + } + tdb_unlock_bystring(service_tdb, vstring); + + DEBUG(0,("Initializing services db\n")); + + svcname = svc_list; + + /* Get the EXTERNAL services as mentioned by line in smb.conf */ + + while (*svcname) { + DEBUG(10,("Reading information on service %s\n",*svcname)); + if (get_LSB_data(*svcname,&si));{ + /* write the information to the TDB */ + store_service_info(service_tdb,*svcname,&si); + /* definitely not efficient to do it this way. */ + pstrcat(external_service_list,"\""); + pstrcat(external_service_list,*svcname); + pstrcat(external_service_list,"\" "); + } + svcname++; + } + pstrcpy(keystring,"EXTERNAL_SERVICES"); + tdb_lock_bystring(service_tdb, keystring, 0); + DEBUG(8,("Storing external service list [%s]\n",external_service_list)); + tdb_store_bystring(service_tdb,keystring,string_tdb_data(external_service_list),TDB_REPLACE); + tdb_unlock_bystring(service_tdb,keystring); + + /* Get the INTERNAL services */ + + pstrcpy(internal_service_list,""); + isd_ptr = ISD; + + while (isd_ptr && (isd_ptr->filename)) { + DEBUG(10,("Reading information on service %s\n",isd_ptr->filename)); + if (get_internal_service_data(isd_ptr,&si)){ + /* write the information to the TDB */ + store_service_info(service_tdb,(char *)isd_ptr->filename,&si); + /* definitely not efficient to do it this way. */ + pstrcat(internal_service_list,"\""); + pstrcat(internal_service_list,isd_ptr->filename); + pstrcat(internal_service_list,"\" "); + + } + isd_ptr++; + } + pstrcpy(keystring,"INTERNAL_SERVICES"); + tdb_lock_bystring(service_tdb, keystring, 0); + DEBUG(8,("Storing internal service list [%s]\n",internal_service_list)); + tdb_store_bystring(service_tdb,keystring,string_tdb_data(internal_service_list),TDB_REPLACE); + tdb_unlock_bystring(service_tdb,keystring); + + return True; +} + diff --git a/source3/services/svc_rcinit.c b/source3/services/svc_rcinit.c new file mode 100644 index 0000000000..a4046b3511 --- /dev/null +++ b/source3/services/svc_rcinit.c @@ -0,0 +1,204 @@ + +/* + * Unix SMB/CIFS implementation. + * Service Control API Implementation + * Copyright (C) Gerald Carter 2005. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* Implementation for LSB compliant init scripts */ + +/******************************************************************************* + Get the services information by reading and parsing the shell scripts. These + are symbolically linked into the SVCCTL_SCRIPT_DIR directory. + + Get the names of the services/scripts to read from the smb.conf file. +*******************************************************************************/ + +BOOL get_LSB_data(char *fname,Service_info *si ) +{ + pstring initdfile; + char mybuffer[256]; + const char *tokenptr; + char **qlines; + int fd = -1; + int nlines, *numlines,i,in_section,in_description; + + pstrcpy(si->servicename,""); + pstrcpy(si->servicetype,"EXTERNAL"); + pstrcpy(si->filename,fname); + pstrcpy(si->provides,""); + pstrcpy(si->dependencies,""); + pstrcpy(si->shouldstart,""); + pstrcpy(si->shouldstop,""); + pstrcpy(si->requiredstart,""); + pstrcpy(si->requiredstop,""); + pstrcpy(si->description,""); + pstrcpy(si->shortdescription,""); + + numlines = &nlines; + in_section = 0; + in_description = 0; + + + if( !fname || !*fname ) { + DEBUG(0, ("Must define an \"LSB-style init file\" to read.\n")); + return False; + } + pstrcpy(initdfile,dyn_LIBDIR); + pstrcat(initdfile,SVCCTL_SCRIPT_DIR); + pstrcat(initdfile,fname); + + /* TODO - should check to see if the file that we're trying to open is + actually a script. If it's NOT, we should do something like warn, + and not continue to try to find info we're looking for */ + + DEBUG(10, ("Opening [%s]\n", initdfile)); + fd = -1; + fd = open(initdfile,O_RDONLY); + *numlines = 0; + + if (fd == -1) { + DEBUG(10, ("Couldn't open [%s]\n", initdfile)); + return False; + } + + qlines = fd_lines_load(fd, numlines); + DEBUGADD(10, ("Lines returned = [%d]\n", *numlines)); + close(fd); + + + if (*numlines) { + + for(i = 0; i < *numlines; i++) { + + DEBUGADD(10, ("Line[%d] = %s\n", i, qlines[i])); + if (!in_section && (0==strwicmp("### BEGIN INIT INFO", qlines[i]))) { + /* we now can look for params */ + DEBUGADD(10, ("Configuration information starts on line = [%d]\n", i)); + in_section = 1; + + } else if (in_section && (0==strwicmp("### END INIT INFO", qlines[i]))) { + DEBUGADD(10, ("Configuration information ends on line = [%d]\n", i)); + DEBUGADD(10, ("Description is [%s]\n", si->description)); + in_description = 0; + in_section = 0; + break; + } else if (in_section) { + tokenptr = qlines[i]; + if (in_description) { + DEBUGADD(10, ("Processing DESCRIPTION [%d]\n", *tokenptr)); + if (tokenptr && (*tokenptr=='#') && (*(tokenptr+1)=='\t')) { + DEBUGADD(10, ("Adding to DESCRIPTION [%d]\n", *tokenptr)); + pstrcat(si->description," "); + pstrcat(si->description,tokenptr+2); + continue; + } + in_description = 0; + DEBUGADD(10, ("Not a description!\n")); + } + if (!next_token(&tokenptr,mybuffer," \t",sizeof(mybuffer))) { + DEBUGADD(10, ("Invalid line [%d]\n", i)); + break; /* bad line? */ + } + if (0 != strncmp(mybuffer,"#",1)) { + DEBUGADD(10, ("Invalid line [%d], is %s\n", i,mybuffer)); + break; + } + if (!next_token(&tokenptr,mybuffer," \t",sizeof(mybuffer))) { + DEBUGADD(10, ("Invalid token on line [%d]\n", i)); + break; /* bad line? */ + } + DEBUGADD(10, ("Keyword is [%s]\n", mybuffer)); + if (0==strwicmp(mybuffer,"Description:")) { + while (tokenptr && *tokenptr && (strchr(" \t",*tokenptr))) { + tokenptr++; + } + pstrcpy(si->description,tokenptr); + DEBUGADD(10, ("FOUND DESCRIPTION! Data is [%s]\n", tokenptr)); + in_description = 1; + } else { + while (tokenptr && *tokenptr && (strchr(" \t",*tokenptr))) { + tokenptr++; + } + DEBUGADD(10, ("Data is [%s]\n", tokenptr)); + in_description = 0; + + /* save certain keywords, don't save others */ + if (0==strwicmp(mybuffer, "Provides:")) { + pstrcpy(si->provides,tokenptr); + pstrcpy(si->servicename,tokenptr); + } + + if (0==strwicmp(mybuffer, "Short-Description:")) { + pstrcpy(si->shortdescription,tokenptr); + } + + if (0==strwicmp(mybuffer, "Required-start:")) { + pstrcpy(si->requiredstart,tokenptr); + pstrcpy(si->dependencies,tokenptr); + } + + if (0==strwicmp(mybuffer, "Should-start:")) { + pstrcpy(si->shouldstart,tokenptr); + } + } + } + } + + file_lines_free(qlines); + return True; + } + + return False; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR rcinit_stop( void ) +{ + return WERR_OK; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR rcinit_start( void ) +{ + return WERR_OK; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR rcinit_status( SERVICE_STATUS *service_status ) +{ + return WERR_OK; +} + +/********************************************************************* +*********************************************************************/ + +/* struct for svcctl control to manipulate rcinit service */ + +SERVICE_CONTROL_OPS rcinit_svc_ops = { + rcinit_stop, + rcinit_start, + rcinit_status +}; diff --git a/source3/services/svc_spoolss.c b/source3/services/svc_spoolss.c new file mode 100644 index 0000000000..991bc0fbfd --- /dev/null +++ b/source3/services/svc_spoolss.c @@ -0,0 +1,58 @@ +/* + * Unix SMB/CIFS implementation. + * Service Control API Implementation + * Copyright (C) Gerald Carter 2005. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* Implementation for internal spoolss service */ + +/********************************************************************* +*********************************************************************/ + +static WERROR spoolss_stop( void ) +{ + return WERR_OK; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR spoolss_start( void ) +{ + return WERR_OK; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR spoolss_status( SERVICE_STATUS *service_status ) +{ + return WERR_OK; +} + +/********************************************************************* +*********************************************************************/ + +/* struct for svcctl control to manipulate spoolss service */ + +SERVICE_CONTROL_OPS spoolss_svc_ops = { + spoolss_stop, + spoolss_start, + spoolss_status +}; -- cgit From 899bc3a07df4ce1f77efc1abce7c3a2e855069e5 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 15 Jun 2005 03:10:36 +0000 Subject: r7603: * fix a bug in the SERVICE_ALL_ACCESS security mask * add calls to start and stop a service (to be filled in by the backend routines in services/svc_*.c (This used to be commit 793d28a946d83beb2576c5c8ce808d32c71c880a) --- source3/services/svc_rcinit.c | 2 +- source3/services/svc_spoolss.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/services') diff --git a/source3/services/svc_rcinit.c b/source3/services/svc_rcinit.c index a4046b3511..c856ae2a99 100644 --- a/source3/services/svc_rcinit.c +++ b/source3/services/svc_rcinit.c @@ -171,7 +171,7 @@ BOOL get_LSB_data(char *fname,Service_info *si ) /********************************************************************* *********************************************************************/ -static WERROR rcinit_stop( void ) +static WERROR rcinit_stop( SERVICE_STATUS *service_status ) { return WERR_OK; } diff --git a/source3/services/svc_spoolss.c b/source3/services/svc_spoolss.c index 991bc0fbfd..bd2f7173f1 100644 --- a/source3/services/svc_spoolss.c +++ b/source3/services/svc_spoolss.c @@ -25,7 +25,7 @@ /********************************************************************* *********************************************************************/ -static WERROR spoolss_stop( void ) +static WERROR spoolss_stop( SERVICE_STATUS *service_status ) { return WERR_OK; } -- cgit From 5b678f7a8469e345a6b25fa19ea1a20fce939a21 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 15 Jun 2005 15:18:18 +0000 Subject: r7610: can successfully stop and start the 'spooler' service by setting the state for the 'disable spoolss' parameter in memory for an individual smbd (This used to be commit f19c10d0c3e7701066b765c712df0636e914bf7e) --- source3/services/svc_spoolss.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source3/services') diff --git a/source3/services/svc_spoolss.c b/source3/services/svc_spoolss.c index bd2f7173f1..5f8fa73ced 100644 --- a/source3/services/svc_spoolss.c +++ b/source3/services/svc_spoolss.c @@ -27,6 +27,16 @@ static WERROR spoolss_stop( SERVICE_STATUS *service_status ) { + ZERO_STRUCTP( service_status ); + + lp_set_spoolss_state( SVCCTL_STOPPED ); + + service_status->type = 0x110; + service_status->state = SVCCTL_STOPPED; + service_status->controls_accepted = SVCCTL_ACCEPT_STOP; + + DEBUG(6,("spoolss_stop: spooler stopped (not really)\n")); + return WERR_OK; } @@ -35,6 +45,13 @@ static WERROR spoolss_stop( SERVICE_STATUS *service_status ) static WERROR spoolss_start( void ) { + /* see if the smb.conf will support this anyways */ + + if ( _lp_disable_spoolss() ) + return WERR_ACCESS_DENIED; + + lp_set_spoolss_state( SVCCTL_RUNNING ); + return WERR_OK; } @@ -43,6 +60,10 @@ static WERROR spoolss_start( void ) static WERROR spoolss_status( SERVICE_STATUS *service_status ) { + service_status->type = 0x110; + service_status->state = lp_get_spoolss_state(); + service_status->controls_accepted = SVCCTL_ACCEPT_STOP; + return WERR_OK; } -- cgit From b162a396fecb08cc02addf17aed30fbc5e813f5b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 16 Jun 2005 00:46:43 +0000 Subject: r7624: * removed unmatched tdb_lock_by_string() call (should fix build farm issues) * comment out services.tdb code until I finish rewriting it (This used to be commit 707b7822286a6c7e9d1e4ca3d15b99c976f6e704) --- source3/services/services_db.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index df74387959..29c5a9f6e6 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -21,6 +21,8 @@ #include "includes.h" +#if 0 + /* backend database routines for services.tdb */ #define SERVICEDB_VERSION_V1 1 /* Will there be more? */ @@ -90,7 +92,6 @@ int num_external_services(void) num_services = 0; } else { pstrcpy(keystring,"EXTERNAL_SERVICES"); - tdb_lock_bystring(service_tdb, keystring, 0); key_data = tdb_fetch_bystring(service_tdb, keystring); if ((key_data.dptr != NULL) && (key_data.dsize != 0)) { @@ -98,7 +99,6 @@ int num_external_services(void) external_services_string[key_data.dsize] = 0; DEBUG(8,("enum_external_services: services list is %s, size is %d\n",external_services_string,key_data.dsize)); } - tdb_unlock_bystring(service_tdb, keystring); } svc_list = str_list_make(external_services_string,NULL); @@ -147,14 +147,12 @@ WERROR enum_external_services(TALLOC_CTX *tcx,ENUM_SERVICES_STATUS **svc_ptr, in DEBUG(8,("enum_external_services: service database is not open!!!\n")); } else { pstrcpy(keystring,"EXTERNAL_SERVICES"); - tdb_lock_bystring(service_tdb, keystring, 0); key_data = tdb_fetch_bystring(service_tdb, keystring); if ((key_data.dptr != NULL) && (key_data.dsize != 0)) { strncpy(external_services_string,key_data.dptr,key_data.dsize); external_services_string[key_data.dsize] = 0; DEBUG(8,("enum_external_services: services list is %s, size is %d\n",external_services_string,key_data.dsize)); } - tdb_unlock_bystring(service_tdb, keystring); } svc_list = str_list_make(external_services_string,NULL); @@ -275,7 +273,6 @@ int num_internal_services(void) num_services = 0; } else { pstrcpy(keystring,"INTERNAL_SERVICES"); - tdb_lock_bystring(service_tdb, keystring, 0); key_data = tdb_fetch_bystring(service_tdb, keystring); if ((key_data.dptr != NULL) && (key_data.dsize != 0)) { @@ -283,7 +280,6 @@ int num_internal_services(void) internal_services_string[key_data.dsize] = 0; DEBUG(8,("enum_internal_services: services list is %s, size is %d\n",internal_services_string,key_data.dsize)); } - tdb_unlock_bystring(service_tdb, keystring); } svc_list = str_list_make(internal_services_string,NULL); @@ -473,7 +469,6 @@ BOOL store_service_info(TDB_CONTEXT *stdb,char *service_name, Service_info *si) tdb_store_bystring(stdb,keystring,string_tdb_data(si->description),TDB_REPLACE); pstr_sprintf(keystring,"SERVICE/%s/SHORTDESC", service_name); - tdb_lock_bystring(stdb, keystring, 0); if (si->shortdescription && *si->shortdescription) tdb_store_bystring(stdb,keystring,string_tdb_data(si->shortdescription),TDB_REPLACE); else @@ -539,10 +534,8 @@ BOOL init_svcctl_db(void) svcname++; } pstrcpy(keystring,"EXTERNAL_SERVICES"); - tdb_lock_bystring(service_tdb, keystring, 0); DEBUG(8,("Storing external service list [%s]\n",external_service_list)); tdb_store_bystring(service_tdb,keystring,string_tdb_data(external_service_list),TDB_REPLACE); - tdb_unlock_bystring(service_tdb,keystring); /* Get the INTERNAL services */ @@ -563,11 +556,9 @@ BOOL init_svcctl_db(void) isd_ptr++; } pstrcpy(keystring,"INTERNAL_SERVICES"); - tdb_lock_bystring(service_tdb, keystring, 0); DEBUG(8,("Storing internal service list [%s]\n",internal_service_list)); tdb_store_bystring(service_tdb,keystring,string_tdb_data(internal_service_list),TDB_REPLACE); - tdb_unlock_bystring(service_tdb,keystring); return True; } - +#endif -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/services/services_db.c | 829 +++++++++++++++++----------------------- source3/services/svc_netlogon.c | 66 ++++ source3/services/svc_rcinit.c | 64 +++- source3/services/svc_spoolss.c | 8 +- source3/services/svc_winreg.c | 63 +++ 5 files changed, 552 insertions(+), 478 deletions(-) create mode 100644 source3/services/svc_netlogon.c create mode 100644 source3/services/svc_winreg.c (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 29c5a9f6e6..b59cd5330e 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -1,8 +1,10 @@ /* * Unix SMB/CIFS implementation. * Service Control API Implementation - * Copyright (C) Gerald Carter 2005. + * * Copyright (C) Marcin Krzysztof Porwit 2005. + * Largely Rewritten by: + * Copyright (C) Gerald (Jerry) Carter 2005. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,544 +23,431 @@ #include "includes.h" -#if 0 - -/* backend database routines for services.tdb */ - -#define SERVICEDB_VERSION_V1 1 /* Will there be more? */ -#define INTERNAL_SERVICES_LIST "NETLOGON Spooler" - -/* */ -/* scripts will execute from the following libdir, if they are in the enable svcctl= */ -/* these should likely be symbolic links. Note that information about them will be extracted from the files themselves */ -/* using the LSB standard keynames for various information */ - -#define SCVCTL_DATABASE_VERSION_V1 1 -static TDB_CONTEXT *service_tdb; /* used for services tdb file */ - -/* there are two types of services -- internal, and external. - Internal services are "built-in" to samba -- there may be - functions that exist to provide the control and enumeration - functions. There certainly is information returned to be - displayed in the typical management console. - - External services are those that can be specified in the smb.conf - file -- and they conform to the LSB specification as to having - particular keywords in the scripts. Note that these "scripts" are - located in the lib directory, and are likely links to LSB-compliant - init.d scripts, such as those that might come with Suse. Note - that the spec is located http://www.linuxbase.org/spec/ */ - - - -/* Expand this to include what can and can't be done - with a particular internal service. Expand as necessary - to add other infromation like what can be controlled, - etc. */ +/******************************************************************** +********************************************************************/ -typedef struct Internal_service_struct +static SEC_DESC* construct_service_sd( TALLOC_CTX *ctx ) { - const char *filename; /* internal name "index" */ - const char *displayname; - const char *description; - const uint32 statustype; - void *status_fn; - void *control_fn; -} Internal_service_description; - + SEC_ACE ace[4]; + SEC_ACCESS mask; + size_t i = 0; + SEC_DESC *sd; + SEC_ACL *acl; + size_t sd_size; + + /* basic access for Everyone */ + + init_sec_access(&mask, SERVICE_READ_ACCESS ); + init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0); + + init_sec_access(&mask,SERVICE_EXECUTE_ACCESS ); + init_sec_ace(&ace[i++], &global_sid_Builtin_Power_Users, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0); + + init_sec_access(&mask,SERVICE_ALL_ACCESS ); + init_sec_ace(&ace[i++], &global_sid_Builtin_Server_Operators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0); + init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0); + + /* create the security descriptor */ + + if ( !(acl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) ) + return NULL; -static const Internal_service_description ISD[] = { - { "NETLOGON", "Net Logon", "Provides logon and authentication service to the network", 0x110, NULL, NULL}, - { "Spooler", "Spooler", "Printing Services", 0x0020, NULL, NULL}, - { NULL, NULL, NULL, 0, NULL, NULL} -}; + if ( !(sd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, acl, &sd_size)) ) + return NULL; + return sd; +} /******************************************************************** - allocate an array of external services and return them. Null return - is okay, make sure &added is also zero! + This is where we do the dirty work of filling in things like the + Display name, Description, etc... ********************************************************************/ -int num_external_services(void) +static void fill_service_values( const char *name, REGVAL_CTR *values ) { - int num_services; - char **svc_list; - pstring keystring, external_services_string; - TDB_DATA key_data; - - - if (!service_tdb) { - DEBUG(8,("enum_external_services: service database is not open!!!\n")); - num_services = 0; - } else { - pstrcpy(keystring,"EXTERNAL_SERVICES"); - key_data = tdb_fetch_bystring(service_tdb, keystring); - - if ((key_data.dptr != NULL) && (key_data.dsize != 0)) { - strncpy(external_services_string,key_data.dptr,key_data.dsize); - external_services_string[key_data.dsize] = 0; - DEBUG(8,("enum_external_services: services list is %s, size is %d\n",external_services_string,key_data.dsize)); - } - } - svc_list = str_list_make(external_services_string,NULL); - - num_services = str_list_count( (const char **)svc_list); + UNISTR2 data, dname, ipath, description; + uint32 dword; + pstring pstr; + + /* These values are hardcoded in all QueryServiceConfig() replies. + I'm just storing them here for cosmetic purposes */ + + dword = SVCCTL_AUTO_START; + regval_ctr_addvalue( values, "Start", REG_DWORD, (char*)&dword, sizeof(uint32)); + + dword = SVCCTL_WIN32_OWN_PROC; + regval_ctr_addvalue( values, "Type", REG_DWORD, (char*)&dword, sizeof(uint32)); - return num_services; + dword = SVCCTL_SVC_ERROR_NORMAL; + regval_ctr_addvalue( values, "ErrorControl", REG_DWORD, (char*)&dword, sizeof(uint32)); + + /* everything runs as LocalSystem */ + + init_unistr2( &data, "LocalSystem", UNI_STR_TERMINATE ); + regval_ctr_addvalue( values, "ObjectName", REG_SZ, (char*)data.buffer, data.uni_str_len*2); + + /* special considerations for internal services and the DisplayName value */ + + if ( strequal(name, "Spooler") ) { + pstr_sprintf( pstr, "%s/%s/smbd",dyn_LIBDIR, SVCCTL_SCRIPT_DIR ); + init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); + init_unistr2( &description, "Internal service for spooling files to print devices", UNI_STR_TERMINATE ); + init_unistr2( &dname, "Print Spooler", UNI_STR_TERMINATE ); + } + else if ( strequal(name, "NETLOGON") ) { + pstr_sprintf( pstr, "%s/%s/smbd",dyn_LIBDIR, SVCCTL_SCRIPT_DIR ); + init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); + init_unistr2( &description, "File service providing access to policy and profile data", UNI_STR_TERMINATE ); + init_unistr2( &dname, "Net Logon", UNI_STR_TERMINATE ); + } + else if ( strequal(name, "RemoteRegistry") ) { + pstr_sprintf( pstr, "%s/%s/smbd",dyn_LIBDIR, SVCCTL_SCRIPT_DIR ); + init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); + init_unistr2( &description, "Internal service providing remote access to the Samba registry", UNI_STR_TERMINATE ); + init_unistr2( &dname, "Remote Registry Service", UNI_STR_TERMINATE ); + } + else { + pstr_sprintf( pstr, "%s/%s/%s",dyn_LIBDIR, SVCCTL_SCRIPT_DIR, name ); + init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); + init_unistr2( &description, "External Unix Service", UNI_STR_TERMINATE ); + init_unistr2( &dname, name, UNI_STR_TERMINATE ); + } + regval_ctr_addvalue( values, "DisplayName", REG_SZ, (char*)dname.buffer, dname.uni_str_len*2); + regval_ctr_addvalue( values, "ImagePath", REG_SZ, (char*)ipath.buffer, ipath.uni_str_len*2); + regval_ctr_addvalue( values, "Description", REG_SZ, (char*)description.buffer, description.uni_str_len*2); + + return; } - - /******************************************************************** - Gather information on the "external services". These are services - listed in the smb.conf file, and found to exist through checks in - this code. Note that added will be incremented on the basis of the - number of services added. svc_ptr should have enough memory allocated - to accommodate all of the services that exist. - - Typically num_external_services is used to "size" the amount of - memory allocated, but does little/no work. - - enum_external_services() actually examines each of the specified - external services, populates the memory structures, and returns. - - ** note that 'added' may end up with less than the number of services - found in _num_external_services, such as the case when a service is - called out, but the actual service doesn't exist or the file can't be - read for the service information. ********************************************************************/ -WERROR enum_external_services(TALLOC_CTX *tcx,ENUM_SERVICES_STATUS **svc_ptr, int existing_services,int *added) +static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, + const char *name ) { - /* *svc_ptr must have pre-allocated memory */ - int num_services = 0; - int i = 0; - ENUM_SERVICES_STATUS *services=NULL; - char **svc_list,**svcname; - pstring command, keystring, external_services_string; - int ret; - int fd = -1; - Service_info *si; - TDB_DATA key_data; - - *added = num_services; - - if (!service_tdb) { - DEBUG(8,("enum_external_services: service database is not open!!!\n")); - } else { - pstrcpy(keystring,"EXTERNAL_SERVICES"); - key_data = tdb_fetch_bystring(service_tdb, keystring); - if ((key_data.dptr != NULL) && (key_data.dsize != 0)) { - strncpy(external_services_string,key_data.dptr,key_data.dsize); - external_services_string[key_data.dsize] = 0; - DEBUG(8,("enum_external_services: services list is %s, size is %d\n",external_services_string,key_data.dsize)); - } - } - svc_list = str_list_make(external_services_string,NULL); - - num_services = str_list_count( (const char **)svc_list); - - if (0 == num_services) { - DEBUG(8,("enum_external_services: there are no external services\n")); - *added = num_services; - return WERR_OK; + REGISTRY_KEY *key_service, *key_secdesc; + WERROR wresult; + pstring path; + REGVAL_CTR *values; + REGSUBKEY_CTR *svc_subkeys; + SEC_DESC *sd; + prs_struct ps; + + /* add to the list and create the subkey path */ + + regsubkey_ctr_addkey( subkeys, name ); + store_reg_keys( key_parent, subkeys ); + + /* open the new service key */ + + pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); + wresult = regkey_open_internal( &key_service, path, get_root_nt_token(), + REG_KEY_ALL ); + if ( !W_ERROR_IS_OK(wresult) ) { + DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", + path, dos_errstr(wresult))); + return; } - DEBUG(8,("enum_external_services: there are [%d] external services\n",num_services)); - si=TALLOC_ARRAY( tcx, Service_info, 1 ); - if (si == NULL) { - DEBUG(8,("enum_external_services: Failed to alloc si\n")); - return WERR_NOMEM; + + /* add the 'Security' key */ + + if ( !(svc_subkeys = TALLOC_ZERO_P( key_service, REGSUBKEY_CTR )) ) { + DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + return; } + + fetch_reg_keys( key_service, svc_subkeys ); + regsubkey_ctr_addkey( svc_subkeys, "Security" ); + store_reg_keys( key_service, svc_subkeys ); -#if 0 -/* *svc_ptr has the pointer to the array if there is one already. NULL if not. */ - if ((existing_services>0) && svc_ptr && *svc_ptr) { /* reallocate vs. allocate */ - DEBUG(8,("enum_external_services: REALLOCing %x to %d services\n", *svc_ptr, existing_services+num_services)); + /* now for the service values */ + + if ( !(values = TALLOC_ZERO_P( key_service, REGVAL_CTR )) ) { + DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + return; + } - services=TALLOC_REALLOC_ARRAY(tcx,*svc_ptr,ENUM_SERVICES_STATUS,existing_services+num_services); - DEBUG(8,("enum_external_services: REALLOCed to %x services\n", services)); + fill_service_values( name, values ); + store_reg_values( key_service, values ); - if (!services) return WERR_NOMEM; - *svc_ptr = services; - } else { - if ( !(services = TALLOC_ARRAY( tcx, ENUM_SERVICES_STATUS, num_services )) ) - return WERR_NOMEM; - } -#endif + /* cleanup the service key*/ + + TALLOC_FREE( key_service ); + + /* now add the security descriptor */ - if (!svc_ptr || !(*svc_ptr)) - return WERR_NOMEM; - services = *svc_ptr; - if (existing_services > 0) { - i+=existing_services; + pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); + wresult = regkey_open_internal( &key_secdesc, path, get_root_nt_token(), + REG_KEY_ALL ); + if ( !W_ERROR_IS_OK(wresult) ) { + DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", + path, dos_errstr(wresult))); + return; } - svcname = svc_list; - DEBUG(8,("enum_external_services: enumerating %d external services starting at index %d\n", num_services,existing_services)); - - while (*svcname) { - DEBUG(10,("enum_external_services: Reading information on service %s, index %d\n",*svcname,i)); - /* get_LSB_data(*svcname,si); */ - if (!get_service_info(service_tdb,*svcname, si)) { - DEBUG(1,("enum_external_services: CAN'T FIND INFO FOR SERVICE %s in the services DB\n",*svcname)); - } - - if ((si->filename == NULL) || (*si->filename == 0)) { - init_unistr(&services[i].servicename, *svcname ); - } else { - init_unistr( &services[i].servicename, si->filename ); - /* init_unistr( &services[i].servicename, si->servicename ); */ - } - - if ((si->provides == NULL) || (*si->provides == 0)) { - init_unistr(&services[i].displayname, *svcname ); - } else { - init_unistr( &services[i].displayname, si->provides ); - } - - /* TODO - we could keep the following info in the DB, too... */ - - DEBUG(8,("enum_external_services: Service name [%s] displayname [%s]\n", - si->filename, si->provides)); - services[i].status.type = SVCCTL_WIN32_OWN_PROC; - services[i].status.win32_exit_code = 0x0; - services[i].status.service_exit_code = 0x0; - services[i].status.check_point = 0x0; - services[i].status.wait_hint = 0x0; - - /* TODO - do callout here to get the status */ - - memset(command, 0, sizeof(command)); - slprintf(command, sizeof(command)-1, "%s%s%s %s", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, *svcname, "status"); - - DEBUG(10, ("enum_external_services: status command is [%s]\n", command)); - - /* TODO - wrap in privilege check */ - - ret = smbrun(command, &fd); - DEBUGADD(10, ("returned [%d]\n", ret)); - close(fd); - if(ret != 0) - DEBUG(10, ("enum_external_services: Command returned [%d]\n", ret)); - services[i].status.state = SVCCTL_STOPPED; - if (ret == 0) { - services[i].status.state = SVCCTL_RUNNING; - services[i].status.controls_accepted = SVCCTL_CONTROL_SHUTDOWN | SVCCTL_CONTROL_STOP; - } else { - services[i].status.state = SVCCTL_STOPPED; - services[i].status.controls_accepted = 0; - } - svcname++; - i++; - } + if ( !(values = TALLOC_ZERO_P( key_secdesc, REGVAL_CTR )) ) { + DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + return; + } - DEBUG(10,("enum_external_services: Read services %d\n",num_services)); - *added = num_services; + if ( !(sd = construct_service_sd(key_secdesc)) ) { + DEBUG(0,("add_new_svc_name: Failed to create default sec_desc!\n")); + TALLOC_FREE( key_secdesc ); + return; + } + + /* stream the printer security descriptor */ + + prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key_secdesc, MARSHALL); + + if ( sec_io_desc("sec_desc", &sd, &ps, 0 ) ) { + uint32 offset = prs_offset( &ps ); + regval_ctr_addvalue( values, "Security", REG_BINARY, prs_data_p(&ps), offset ); + store_reg_values( key_secdesc, values ); + } + + /* finally cleanup the Security key */ + + prs_mem_free( &ps ); + TALLOC_FREE( key_secdesc ); - return WERR_OK; + return; } /******************************************************************** ********************************************************************/ -int num_internal_services(void) +void svcctl_init_keys( void ) { - int num_services; - char **svc_list; - pstring keystring, internal_services_string; - TDB_DATA key_data; - - if (!service_tdb) { - DEBUG(8,("enum_internal_services: service database is not open!!!\n")); - num_services = 0; - } else { - pstrcpy(keystring,"INTERNAL_SERVICES"); - key_data = tdb_fetch_bystring(service_tdb, keystring); - - if ((key_data.dptr != NULL) && (key_data.dsize != 0)) { - strncpy(internal_services_string,key_data.dptr,key_data.dsize); - internal_services_string[key_data.dsize] = 0; - DEBUG(8,("enum_internal_services: services list is %s, size is %d\n",internal_services_string,key_data.dsize)); - } - } - svc_list = str_list_make(internal_services_string,NULL); - - num_services = str_list_count( (const char **)svc_list); - - return num_services; -} - -#if 0 -/********************************************************************* - given a service nice name, find the underlying service name -*********************************************************************/ - -static BOOL convert_service_displayname(TDB_CONTEXT *stdb,pstring service_nicename, pstring servicename,int szsvcname) -{ - pstring keystring; - TDB_DATA key_data; - - if ((stdb == NULL) || (service_nicename==NULL) || (servicename == NULL)) - return False; + const char **service_list = lp_svcctl_list(); + int i; + REGSUBKEY_CTR *subkeys; + REGISTRY_KEY *key = NULL; + WERROR wresult; + BOOL new_services = False; + + /* bad mojo here if the lookup failed. Should not happen */ + + wresult = regkey_open_internal( &key, KEY_SERVICES, get_root_nt_token(), + REG_KEY_ALL ); - pstr_sprintf(keystring,"SERVICE_NICENAME/%s", servicename); + if ( !W_ERROR_IS_OK(wresult) ) { + DEBUG(0,("init_services_keys: key lookup failed! (%s)\n", + dos_errstr(wresult))); + return; + } + + /* lookup the available subkeys */ + + if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) { + DEBUG(0,("init_services_keys: talloc() failed!\n")); + return; + } + + fetch_reg_keys( key, subkeys ); + + /* the builting services exist */ + + add_new_svc_name( key, subkeys, "Spooler" ); + add_new_svc_name( key, subkeys, "NETLOGON" ); + add_new_svc_name( key, subkeys, "RemoteRegistry" ); + + for ( i=0; service_list[i]; i++ ) { + + /* only add new services */ + if ( regsubkey_ctr_key_exists( subkeys, service_list[i] ) ) + continue; - DEBUG(5, ("convert_service_displayname: Looking for service name [%s], key [%s]\n", - service_nicename, keystring)); + /* Add the new service key and initialize the appropriate values */ - key_data = tdb_fetch_bystring(stdb,keystring); + add_new_svc_name( key, subkeys, service_list[i] ); - if (key_data.dsize == 0) { - DEBUG(5, ("convert_service_displayname: [%s] Not found, tried key [%s]\n",service_nicename,keystring)); - return False; + new_services = True; } - strncpy(servicename,key_data.dptr,szsvcname); - servicename[(key_data.dsize > szsvcname ? szsvcname : key_data.dsize)] = 0; - DEBUG(5, ("convert_service_displayname: Found service name [%s], name is [%s]\n", - service_nicename,servicename)); + TALLOC_FREE( key ); - return True; -} -#endif + /* initialize the control hooks */ -/******************************************************************************* - Get the INTERNAL services information for the given service name. -*******************************************************************************/ + init_service_op_table(); -static BOOL get_internal_service_data(const Internal_service_description *isd, Service_info *si) -{ - ZERO_STRUCTP( si ); -#if 0 - - pstrcpy( si->servicename, isd->displayname); - pstrcpy( si->servicetype, "INTERNAL"); - pstrcpy( si->filename, isd->filename); - pstrcpy( si->provides, isd->displayname); - pstrcpy( si->description, isd->description); - pstrcpy( si->shortdescription, isd->description); -#endif - - return True; + return; } /******************************************************************** + This is where we do the dirty work of filling in things like the + Display name, Description, etc...Always return a default secdesc + in case of any failure. ********************************************************************/ -BOOL get_service_info(TDB_CONTEXT *stdb,char *service_name, Service_info *si) -{ - - pstring keystring; - TDB_DATA key_data; - - if ((stdb == NULL) || (si == NULL) || (service_name==NULL) || (*service_name == 0)) - return False; - - /* TODO - error handling -- what if the service isn't in the DB? */ - - pstr_sprintf(keystring,"SERVICE/%s/TYPE", service_name); - key_data = tdb_fetch_bystring(stdb,keystring); - strncpy(si->servicetype,key_data.dptr,key_data.dsize); - si->servicetype[key_data.dsize] = 0; - - /* crude check to see if the service exists... */ - DEBUG(3,("Size of the TYPE field is %d\n",key_data.dsize)); - if (key_data.dsize == 0) - return False; - - pstr_sprintf(keystring,"SERVICE/%s/FILENAME", service_name); - key_data = tdb_fetch_bystring(stdb,keystring); - strncpy(si->filename,key_data.dptr,key_data.dsize); - si->filename[key_data.dsize] = 0; - - pstr_sprintf(keystring,"SERVICE/%s/PROVIDES", service_name); - key_data = tdb_fetch_bystring(stdb,keystring); - strncpy(si->provides,key_data.dptr,key_data.dsize); - si->provides[key_data.dsize] = 0; - strncpy(si->servicename,key_data.dptr,key_data.dsize); - si->servicename[key_data.dsize] = 0; - - - pstr_sprintf(keystring,"SERVICE/%s/DEPENDENCIES", service_name); - key_data = tdb_fetch_bystring(stdb,keystring); - strncpy(si->dependencies,key_data.dptr,key_data.dsize); - si->dependencies[key_data.dsize] = 0; - - pstr_sprintf(keystring,"SERVICE/%s/SHOULDSTART", service_name); - key_data = tdb_fetch_bystring(stdb,keystring); - strncpy(si->shouldstart,key_data.dptr,key_data.dsize); - si->shouldstart[key_data.dsize] = 0; - - pstr_sprintf(keystring,"SERVICE/%s/SHOULD_STOP", service_name); - key_data = tdb_fetch_bystring(stdb,keystring); - strncpy(si->shouldstop,key_data.dptr,key_data.dsize); - si->shouldstop[key_data.dsize] = 0; - - pstr_sprintf(keystring,"SERVICE/%s/REQUIREDSTART", service_name); - key_data = tdb_fetch_bystring(stdb,keystring); - strncpy(si->requiredstart,key_data.dptr,key_data.dsize); - si->requiredstart[key_data.dsize] = 0; - - pstr_sprintf(keystring,"SERVICE/%s/REQUIREDSTOP", service_name); - key_data = tdb_fetch_bystring(stdb,keystring); - strncpy(si->requiredstop,key_data.dptr,key_data.dsize); - si->requiredstop[key_data.dsize] = 0; - - pstr_sprintf(keystring,"SERVICE/%s/DESCRIPTION", service_name); - key_data = tdb_fetch_bystring(stdb,keystring); - strncpy(si->description,key_data.dptr,key_data.dsize); - si->description[key_data.dsize] = 0; - - pstr_sprintf(keystring,"SERVICE/%s/SHORTDESC", service_name); - key_data = tdb_fetch_bystring(stdb,keystring); - strncpy(si->shortdescription,key_data.dptr,key_data.dsize); - si->shortdescription[key_data.dsize] = 0; - - return True; -} - -/********************************************************************* -*********************************************************************/ - -BOOL store_service_info(TDB_CONTEXT *stdb,char *service_name, Service_info *si) +SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token ) { - pstring keystring; - - /* Note -- when we write to the tdb, we "index" on the filename - field, not the nice name. when a service is "opened", it is - opened by the nice (SERVICENAME) name, not the file name. - So there needs to be a mapping from nice name back to the file name. */ - - if ((stdb == NULL) || (si == NULL) || (service_name==NULL) || (*service_name == 0)) - return False; - - - /* Store the nicename */ - - pstr_sprintf(keystring,"SERVICE_NICENAME/%s", si->servicename); - tdb_store_bystring(stdb,keystring,string_tdb_data(service_name),TDB_REPLACE); - - pstr_sprintf(keystring,"SERVICE/%s/TYPE", service_name); - tdb_store_bystring(stdb,keystring,string_tdb_data(si->servicetype),TDB_REPLACE); - - pstr_sprintf(keystring,"SERVICE/%s/FILENAME", service_name); - tdb_store_bystring(stdb,keystring,string_tdb_data(si->filename),TDB_REPLACE); - - pstr_sprintf(keystring,"SERVICE/%s/PROVIDES", service_name); - tdb_store_bystring(stdb,keystring,string_tdb_data(si->provides),TDB_REPLACE); + REGISTRY_KEY *key; + prs_struct ps; + REGVAL_CTR *values; + REGISTRY_VALUE *val; + SEC_DESC *sd = NULL; + SEC_DESC *ret_sd = NULL; + pstring path; + WERROR wresult; + + /* now add the security descriptor */ + + pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + if ( !W_ERROR_IS_OK(wresult) ) { + DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", + path, dos_errstr(wresult))); + return NULL; + } - pstr_sprintf(keystring,"SERVICE/%s/SERVICENAME", service_name); - tdb_store_bystring(stdb,keystring,string_tdb_data(si->servicename),TDB_REPLACE); + if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { + DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + TALLOC_FREE( key ); + return NULL; + } - pstr_sprintf(keystring,"SERVICE/%s/DEPENDENCIES", service_name); - tdb_store_bystring(stdb,keystring,string_tdb_data(si->dependencies),TDB_REPLACE); + fetch_reg_values( key, values ); + + if ( !(val = regval_ctr_getvalue( values, "Security" )) ) { + DEBUG(6,("svcctl_get_secdesc: constructing default secdesc for service [%s]\n", + name)); + TALLOC_FREE( key ); + return construct_service_sd( ctx ); + } + - pstr_sprintf(keystring,"SERVICE/%s/SHOULDSTART", service_name); - tdb_store_bystring(stdb,keystring,string_tdb_data(si->shouldstart),TDB_REPLACE); + /* stream the printer security descriptor */ + + prs_init( &ps, 0, key, UNMARSHALL); + prs_give_memory( &ps, regval_data_p(val), regval_size(val), False ); + + if ( !sec_io_desc("sec_desc", &sd, &ps, 0 ) ) { + TALLOC_FREE( key ); + return construct_service_sd( ctx ); + } + + ret_sd = dup_sec_desc( ctx, sd ); + + /* finally cleanup the Security key */ + + prs_mem_free( &ps ); + TALLOC_FREE( key ); - pstr_sprintf(keystring,"SERVICE/%s/SHOULDSTOP", service_name); - tdb_store_bystring(stdb,keystring,string_tdb_data(si->shouldstop),TDB_REPLACE); + return ret_sd; +} - pstr_sprintf(keystring,"SERVICE/%s/REQUIREDSTART", service_name); - tdb_store_bystring(stdb,keystring,string_tdb_data(si->requiredstart),TDB_REPLACE); +/******************************************************************** +********************************************************************/ - pstr_sprintf(keystring,"SERVICE/%s/REQUIREDSTOP", service_name); - tdb_store_bystring(stdb,keystring,string_tdb_data(si->requiredstop),TDB_REPLACE); +char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) +{ + static fstring display_name; + REGISTRY_KEY *key; + REGVAL_CTR *values; + REGISTRY_VALUE *val; + pstring path; + WERROR wresult; + + /* now add the security descriptor */ + + pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + if ( !W_ERROR_IS_OK(wresult) ) { + DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", + path, dos_errstr(wresult))); + return NULL; + } - pstr_sprintf(keystring,"SERVICE/%s/DESCRIPTION", service_name); - tdb_store_bystring(stdb,keystring,string_tdb_data(si->description),TDB_REPLACE); + if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { + DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n")); + TALLOC_FREE( key ); + return NULL; + } - pstr_sprintf(keystring,"SERVICE/%s/SHORTDESC", service_name); - if (si->shortdescription && *si->shortdescription) - tdb_store_bystring(stdb,keystring,string_tdb_data(si->shortdescription),TDB_REPLACE); + fetch_reg_values( key, values ); + + if ( !(val = regval_ctr_getvalue( values, "DisplayName" )) ) + fstrcpy( display_name, name ); else - tdb_store_bystring(stdb,keystring,string_tdb_data(si->description),TDB_REPLACE); + rpcstr_pull( display_name, regval_data_p(val), sizeof(display_name), regval_size(val), 0 ); - return True; + TALLOC_FREE( key ); + + return display_name; } -/**************************************************************************** - Create/Open the service control manager tdb. This code a clone of init_group_mapping. -****************************************************************************/ +/******************************************************************** +********************************************************************/ -BOOL init_svcctl_db(void) +char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) { - const char *vstring = "INFO/version"; - uint32 vers_id; - char **svc_list; - char **svcname; - pstring keystring; - pstring external_service_list; - pstring internal_service_list; - Service_info si; - const Internal_service_description *isd_ptr; - /* svc_list = str_list_make( "etc/init.d/skeleton etc/init.d/syslog", NULL ); */ - svc_list=(char **)lp_enable_svcctl(); - - if (service_tdb) - return True; - - pstrcpy(external_service_list,""); - - service_tdb = tdb_open_log(lock_path("services.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600); - if (!service_tdb) { - DEBUG(0,("Failed to open service db\n")); - service_tdb = tdb_open_log(lock_path("services.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); - if (!service_tdb) return False; - DEBUG(0,("Created new services db\n")); + static fstring description; + REGISTRY_KEY *key; + REGVAL_CTR *values; + REGISTRY_VALUE *val; + pstring path; + WERROR wresult; + + /* now add the security descriptor */ + + pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + if ( !W_ERROR_IS_OK(wresult) ) { + DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", + path, dos_errstr(wresult))); + return NULL; } - if ((-1 == tdb_fetch_uint32(service_tdb, vstring,&vers_id)) || (vers_id != SERVICEDB_VERSION_V1)) { - /* wrong version of DB, or db was just created */ - tdb_traverse(service_tdb, tdb_traverse_delete_fn, NULL); - tdb_store_uint32(service_tdb, vstring, SERVICEDB_VERSION_V1); + if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { + DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n")); + TALLOC_FREE( key ); + return NULL; } - tdb_unlock_bystring(service_tdb, vstring); - DEBUG(0,("Initializing services db\n")); + fetch_reg_values( key, values ); + + if ( !(val = regval_ctr_getvalue( values, "Description" )) ) + fstrcpy( description, "Unix Service"); + else + rpcstr_pull( description, regval_data_p(val), sizeof(description), regval_size(val), 0 ); + + TALLOC_FREE( key ); - svcname = svc_list; + return description; +} - /* Get the EXTERNAL services as mentioned by line in smb.conf */ - while (*svcname) { - DEBUG(10,("Reading information on service %s\n",*svcname)); - if (get_LSB_data(*svcname,&si));{ - /* write the information to the TDB */ - store_service_info(service_tdb,*svcname,&si); - /* definitely not efficient to do it this way. */ - pstrcat(external_service_list,"\""); - pstrcat(external_service_list,*svcname); - pstrcat(external_service_list,"\" "); - } - svcname++; +/******************************************************************** +********************************************************************/ + +REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token ) +{ + REGISTRY_KEY *key; + REGVAL_CTR *values; + pstring path; + WERROR wresult; + + /* now add the security descriptor */ + + pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + if ( !W_ERROR_IS_OK(wresult) ) { + DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n", + path, dos_errstr(wresult))); + return NULL; } - pstrcpy(keystring,"EXTERNAL_SERVICES"); - DEBUG(8,("Storing external service list [%s]\n",external_service_list)); - tdb_store_bystring(service_tdb,keystring,string_tdb_data(external_service_list),TDB_REPLACE); - - /* Get the INTERNAL services */ - - pstrcpy(internal_service_list,""); - isd_ptr = ISD; - - while (isd_ptr && (isd_ptr->filename)) { - DEBUG(10,("Reading information on service %s\n",isd_ptr->filename)); - if (get_internal_service_data(isd_ptr,&si)){ - /* write the information to the TDB */ - store_service_info(service_tdb,(char *)isd_ptr->filename,&si); - /* definitely not efficient to do it this way. */ - pstrcat(internal_service_list,"\""); - pstrcat(internal_service_list,isd_ptr->filename); - pstrcat(internal_service_list,"\" "); - - } - isd_ptr++; + + if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) { + DEBUG(0,("svcctl_fetch_regvalues: talloc() failed!\n")); + TALLOC_FREE( key ); + return NULL; } - pstrcpy(keystring,"INTERNAL_SERVICES"); - DEBUG(8,("Storing internal service list [%s]\n",internal_service_list)); - tdb_store_bystring(service_tdb,keystring,string_tdb_data(internal_service_list),TDB_REPLACE); + + fetch_reg_values( key, values ); - return True; + TALLOC_FREE( key ); + + return values; } -#endif + diff --git a/source3/services/svc_netlogon.c b/source3/services/svc_netlogon.c new file mode 100644 index 0000000000..2aa5a31cde --- /dev/null +++ b/source3/services/svc_netlogon.c @@ -0,0 +1,66 @@ +/* + * Unix SMB/CIFS implementation. + * Service Control API Implementation + * Copyright (C) Gerald Carter 2005. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* Implementation for internal netlogon service */ + +/********************************************************************* +*********************************************************************/ + +static WERROR netlogon_stop( const char *service, SERVICE_STATUS *service_status ) +{ + return WERR_ACCESS_DENIED; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR netlogon_start( const char *service ) +{ + return WERR_ACCESS_DENIED; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR netlogon_status( const char *service, SERVICE_STATUS *service_status ) +{ + ZERO_STRUCTP( service_status ); + + service_status->type = 0x20; + if ( lp_servicenumber("NETLOGON") != -1 ) + service_status->state = SVCCTL_RUNNING; + else + service_status->state = SVCCTL_STOPPED; + + return WERR_OK; +} + +/********************************************************************* +*********************************************************************/ + +/* struct for svcctl control to manipulate netlogon service */ + +SERVICE_CONTROL_OPS netlogon_svc_ops = { + netlogon_stop, + netlogon_start, + netlogon_status +}; diff --git a/source3/services/svc_rcinit.c b/source3/services/svc_rcinit.c index c856ae2a99..5801d076c4 100644 --- a/source3/services/svc_rcinit.c +++ b/source3/services/svc_rcinit.c @@ -171,24 +171,78 @@ BOOL get_LSB_data(char *fname,Service_info *si ) /********************************************************************* *********************************************************************/ -static WERROR rcinit_stop( SERVICE_STATUS *service_status ) +static WERROR rcinit_stop( const char *service, SERVICE_STATUS *status ) { - return WERR_OK; + pstring command; + int ret, fd; + + pstr_sprintf( command, "%s/%s/%s stop", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service ); + + /* we've already performed the access check when the service was opened */ + + become_root(); + ret = smbrun( command , &fd ); + unbecome_root(); + + DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret)); + close(fd); + + ZERO_STRUCTP( status ); + status->type = 0x0020; + status->state = (ret == 0 ) ? 0x0001 : 0x0004; + status->controls_accepted = 0x0005; + + return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED; } /********************************************************************* *********************************************************************/ -static WERROR rcinit_start( void ) +static WERROR rcinit_start( const char *service ) { - return WERR_OK; + pstring command; + int ret, fd; + + pstr_sprintf( command, "%s/%s/%s start", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service ); + + /* we've already performed the access check when the service was opened */ + + become_root(); + ret = smbrun( command , &fd ); + unbecome_root(); + + DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret)); + close(fd); + + return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED; } /********************************************************************* *********************************************************************/ -static WERROR rcinit_status( SERVICE_STATUS *service_status ) +static WERROR rcinit_status( const char *service, SERVICE_STATUS *status ) { + pstring command; + int ret, fd; + + pstr_sprintf( command, "%s/%s/%s status", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service ); + + /* we've already performed the access check when the service was opened */ + /* assume as return code of 0 means that the service is ok. Anything else + is STOPPED */ + + become_root(); + ret = smbrun( command , &fd ); + unbecome_root(); + + DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret)); + close(fd); + + ZERO_STRUCTP( status ); + status->type = 0x0020; + status->state = (ret == 0 ) ? 0x0004 : 0x0001; + status->controls_accepted = 0x0005; + return WERR_OK; } diff --git a/source3/services/svc_spoolss.c b/source3/services/svc_spoolss.c index 5f8fa73ced..13a1dbb1bd 100644 --- a/source3/services/svc_spoolss.c +++ b/source3/services/svc_spoolss.c @@ -25,7 +25,7 @@ /********************************************************************* *********************************************************************/ -static WERROR spoolss_stop( SERVICE_STATUS *service_status ) +static WERROR spoolss_stop( const char *service, SERVICE_STATUS *service_status ) { ZERO_STRUCTP( service_status ); @@ -43,7 +43,7 @@ static WERROR spoolss_stop( SERVICE_STATUS *service_status ) /********************************************************************* *********************************************************************/ -static WERROR spoolss_start( void ) +static WERROR spoolss_start( const char *service ) { /* see if the smb.conf will support this anyways */ @@ -58,8 +58,10 @@ static WERROR spoolss_start( void ) /********************************************************************* *********************************************************************/ -static WERROR spoolss_status( SERVICE_STATUS *service_status ) +static WERROR spoolss_status( const char *service, SERVICE_STATUS *service_status ) { + ZERO_STRUCTP( service_status ); + service_status->type = 0x110; service_status->state = lp_get_spoolss_state(); service_status->controls_accepted = SVCCTL_ACCEPT_STOP; diff --git a/source3/services/svc_winreg.c b/source3/services/svc_winreg.c new file mode 100644 index 0000000000..1bccee246e --- /dev/null +++ b/source3/services/svc_winreg.c @@ -0,0 +1,63 @@ +/* + * Unix SMB/CIFS implementation. + * Service Control API Implementation + * Copyright (C) Gerald Carter 2005. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* Implementation for internal winreg service */ + +/********************************************************************* +*********************************************************************/ + +static WERROR winreg_stop( const char *service, SERVICE_STATUS *service_status ) +{ + return WERR_ACCESS_DENIED; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR winreg_start( const char *service ) +{ + return WERR_ACCESS_DENIED; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR winreg_status( const char *service, SERVICE_STATUS *service_status ) +{ + ZERO_STRUCTP( service_status ); + + service_status->type = 0x20; + service_status->state = SVCCTL_RUNNING; + + return WERR_OK; +} + +/********************************************************************* +*********************************************************************/ + +/* struct for svcctl control to manipulate winreg service */ + +SERVICE_CONTROL_OPS winreg_svc_ops = { + winreg_stop, + winreg_start, + winreg_status +}; -- cgit From 0bf72b6e330a76bee502cb36c1cb80c46d47d33c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 6 Oct 2005 17:48:03 +0000 Subject: r10781: merging eventlog and svcctl code from trunk (This used to be commit f10aa9fb84bfac4f1a22b74d63999668700ffaac) --- source3/services/services_db.c | 238 +++++++++++++++++++++++++++++++++++------ source3/services/svc_rcinit.c | 148 ------------------------- source3/services/svc_wins.c | 66 ++++++++++++ 3 files changed, 273 insertions(+), 179 deletions(-) create mode 100644 source3/services/svc_wins.c (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index b59cd5330e..7c75d41352 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -23,6 +23,58 @@ #include "includes.h" +struct rcinit_file_information { + char *description; +}; + +struct service_display_info { + const char *servicename; + const char *daemon; + const char *dispname; + const char *description; +}; + +struct service_display_info builtin_svcs[] = { + { "Spooler", "smbd", "Print Spooler", + "Internal service for spooling files to print devices" }, + { "NETLOGON", "smbd", "Net Logon", + "File service providing access to policy and profile data" }, + { "RemoteRegistry", "smbd", "Remote Registry Service", + "Internal service providing remote access to the Samba registry" }, + { "WINS", "nmbd", "Windows Internet Name Service (WINS)", + "Internal service providing a NetBIOS point-to-point name server" }, + { NULL, NULL, NULL, NULL } +}; + +struct service_display_info common_unix_svcs[] = { + { "cups", NULL, "Common Unix Printing System", NULL }, + { "postfix", NULL, "Internet Mail Service", NULL }, + { "sendmail", NULL, "Internet Mail Service", NULL }, + { "portmap", NULL, "TCP Port to RPC PortMapper", NULL }, + { "xinetd", NULL, "Internet Meta-Daemon", NULL }, + { "inet", NULL, "Internet Meta-Daemon", NULL }, + { "xntpd", NULL, "Network Time Service", NULL }, + { "ntpd", NULL, "Network Time Service", NULL }, + { "lpd", NULL, "BSD Print Spooler", NULL }, + { "nfsserver", NULL, "Network File Service", NULL }, + { "cron", NULL, "Scheduling Service", NULL }, + { "at", NULL, "Scheduling Service", NULL }, + { "nscd", NULL, "Name Service Cache Daemon", NULL }, + { "slapd", NULL, "LDAP Directory Service", NULL }, + { "ldap", NULL, "LDAP DIrectory Service", NULL }, + { "ypbind", NULL, "NIS Directory Service", NULL }, + { "courier-imap", NULL, "IMAP4 Mail Service", NULL }, + { "courier-pop3", NULL, "POP3 Mail Service", NULL }, + { "named", NULL, "Domain Name Service", NULL }, + { "bind", NULL, "Domain Name Service", NULL }, + { "httpd", NULL, "HTTP Server", NULL }, + { "apache", NULL, "HTTP Server", NULL }, + { "autofs", NULL, "Automounter", NULL }, + { "squid", NULL, "Web Cache Proxy ", NULL }, + { NULL, NULL, NULL, NULL } +}; + + /******************************************************************** ********************************************************************/ @@ -63,11 +115,122 @@ static SEC_DESC* construct_service_sd( TALLOC_CTX *ctx ) Display name, Description, etc... ********************************************************************/ +static char *get_common_service_dispname( const char *servicename ) +{ + static fstring dispname; + int i; + + for ( i=0; common_unix_svcs[i].servicename; i++ ) { + if ( strequal( servicename, common_unix_svcs[i].servicename ) ) { + fstr_sprintf( dispname, "%s (%s)", + common_unix_svcs[i].dispname, + common_unix_svcs[i].servicename ); + + return dispname; + } + } + + fstrcpy( dispname, servicename ); + + return dispname; +} + +/******************************************************************** +********************************************************************/ + +static char* cleanup_string( const char *string ) +{ + static pstring clean; + char *begin, *end; + + pstrcpy( clean, string ); + begin = clean; + + /* trim any beginning whilespace */ + + while ( isspace(*begin) ) + begin++; + + if ( !begin ) + return NULL; + + /* trim any trailing whitespace or carriage returns. + Start at the end and move backwards */ + + end = begin + strlen(begin) - 1; + + while ( isspace(*end) || *end=='\n' || *end=='\r' ) { + *end = '\0'; + end--; + } + + return begin; +} + +/******************************************************************** +********************************************************************/ + +static BOOL read_init_file( const char *servicename, struct rcinit_file_information **service_info ) +{ + struct rcinit_file_information *info; + pstring filepath, str; + XFILE *f; + char *p, *s; + + if ( !(info = TALLOC_ZERO_P( NULL, struct rcinit_file_information ) ) ) + return False; + + /* attempt the file open */ + + pstr_sprintf( filepath, "%s/%s/%s", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, servicename ); + if ( !(f = x_fopen( filepath, O_RDONLY, 0 )) ) { + DEBUG(0,("read_init_file: failed to open [%s]\n", filepath)); + TALLOC_FREE(info); + return False; + } + + while ( (s = x_fgets( str, sizeof(str)-1, f )) != NULL ) { + /* ignore everything that is not a full line + comment starting with a '#' */ + + if ( str[0] != '#' ) + continue; + + /* Look for a line like '^#.*Description:' */ + + if ( (p = strstr( str, "Description:" )) != NULL ) { + char *desc; + + p += strlen( "Description:" ) + 1; + if ( !p ) + break; + + if ( (desc = cleanup_string(p)) != NULL ) + info->description = talloc_strdup( info, desc ); + } + } + + x_fclose( f ); + + if ( !info->description ) + info->description = talloc_strdup( info, "External Unix Service" ); + + *service_info = info; + + return True; +} + +/******************************************************************** + This is where we do the dirty work of filling in things like the + Display name, Description, etc... +********************************************************************/ + static void fill_service_values( const char *name, REGVAL_CTR *values ) { UNISTR2 data, dname, ipath, description; uint32 dword; pstring pstr; + int i; /* These values are hardcoded in all QueryServiceConfig() replies. I'm just storing them here for cosmetic purposes */ @@ -88,30 +251,39 @@ static void fill_service_values( const char *name, REGVAL_CTR *values ) /* special considerations for internal services and the DisplayName value */ - if ( strequal(name, "Spooler") ) { - pstr_sprintf( pstr, "%s/%s/smbd",dyn_LIBDIR, SVCCTL_SCRIPT_DIR ); - init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); - init_unistr2( &description, "Internal service for spooling files to print devices", UNI_STR_TERMINATE ); - init_unistr2( &dname, "Print Spooler", UNI_STR_TERMINATE ); - } - else if ( strequal(name, "NETLOGON") ) { - pstr_sprintf( pstr, "%s/%s/smbd",dyn_LIBDIR, SVCCTL_SCRIPT_DIR ); - init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); - init_unistr2( &description, "File service providing access to policy and profile data", UNI_STR_TERMINATE ); - init_unistr2( &dname, "Net Logon", UNI_STR_TERMINATE ); + for ( i=0; builtin_svcs[i].servicename; i++ ) { + if ( strequal( name, builtin_svcs[i].servicename ) ) { + pstr_sprintf( pstr, "%s/%s/%s",dyn_LIBDIR, SVCCTL_SCRIPT_DIR, builtin_svcs[i].daemon ); + init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); + init_unistr2( &description, builtin_svcs[i].description, UNI_STR_TERMINATE ); + init_unistr2( &dname, builtin_svcs[i].dispname, UNI_STR_TERMINATE ); + break; + } } - else if ( strequal(name, "RemoteRegistry") ) { - pstr_sprintf( pstr, "%s/%s/smbd",dyn_LIBDIR, SVCCTL_SCRIPT_DIR ); - init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); - init_unistr2( &description, "Internal service providing remote access to the Samba registry", UNI_STR_TERMINATE ); - init_unistr2( &dname, "Remote Registry Service", UNI_STR_TERMINATE ); - } - else { + + /* default to an external service if we haven't found a match */ + + if ( builtin_svcs[i].servicename == NULL ) { + struct rcinit_file_information *init_info = NULL; + pstr_sprintf( pstr, "%s/%s/%s",dyn_LIBDIR, SVCCTL_SCRIPT_DIR, name ); init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); - init_unistr2( &description, "External Unix Service", UNI_STR_TERMINATE ); - init_unistr2( &dname, name, UNI_STR_TERMINATE ); + + /* lookup common unix display names */ + init_unistr2( &dname, get_common_service_dispname( name ), UNI_STR_TERMINATE ); + + /* get info from init file itself */ + if ( read_init_file( name, &init_info ) ) { + init_unistr2( &description, init_info->description, UNI_STR_TERMINATE ); + TALLOC_FREE( init_info ); + } + else { + init_unistr2( &description, "External Unix Service", UNI_STR_TERMINATE ); + } } + + /* add the new values */ + regval_ctr_addvalue( values, "DisplayName", REG_SZ, (char*)dname.buffer, dname.uni_str_len*2); regval_ctr_addvalue( values, "ImagePath", REG_SZ, (char*)ipath.buffer, ipath.uni_str_len*2); regval_ctr_addvalue( values, "Description", REG_SZ, (char*)description.buffer, description.uni_str_len*2); @@ -248,9 +420,8 @@ void svcctl_init_keys( void ) /* the builting services exist */ - add_new_svc_name( key, subkeys, "Spooler" ); - add_new_svc_name( key, subkeys, "NETLOGON" ); - add_new_svc_name( key, subkeys, "RemoteRegistry" ); + for ( i=0; builtin_svcs[i].servicename; i++ ) + add_new_svc_name( key, subkeys, builtin_svcs[i].servicename ); for ( i=0; service_list[i]; i++ ) { @@ -352,29 +523,34 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); - return NULL; + goto fail; } if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n")); TALLOC_FREE( key ); - return NULL; + goto fail; } fetch_reg_values( key, values ); if ( !(val = regval_ctr_getvalue( values, "DisplayName" )) ) - fstrcpy( display_name, name ); - else - rpcstr_pull( display_name, regval_data_p(val), sizeof(display_name), regval_size(val), 0 ); + goto fail; + + rpcstr_pull( display_name, regval_data_p(val), sizeof(display_name), regval_size(val), 0 ); TALLOC_FREE( key ); return display_name; + +fail: + /* default to returning the service name */ + fstrcpy( display_name, name ); + return display_name; } /******************************************************************** @@ -392,7 +568,7 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -431,7 +607,7 @@ REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); diff --git a/source3/services/svc_rcinit.c b/source3/services/svc_rcinit.c index 5801d076c4..f60019601f 100644 --- a/source3/services/svc_rcinit.c +++ b/source3/services/svc_rcinit.c @@ -1,4 +1,3 @@ - /* * Unix SMB/CIFS implementation. * Service Control API Implementation @@ -21,153 +20,6 @@ #include "includes.h" -/* Implementation for LSB compliant init scripts */ - -/******************************************************************************* - Get the services information by reading and parsing the shell scripts. These - are symbolically linked into the SVCCTL_SCRIPT_DIR directory. - - Get the names of the services/scripts to read from the smb.conf file. -*******************************************************************************/ - -BOOL get_LSB_data(char *fname,Service_info *si ) -{ - pstring initdfile; - char mybuffer[256]; - const char *tokenptr; - char **qlines; - int fd = -1; - int nlines, *numlines,i,in_section,in_description; - - pstrcpy(si->servicename,""); - pstrcpy(si->servicetype,"EXTERNAL"); - pstrcpy(si->filename,fname); - pstrcpy(si->provides,""); - pstrcpy(si->dependencies,""); - pstrcpy(si->shouldstart,""); - pstrcpy(si->shouldstop,""); - pstrcpy(si->requiredstart,""); - pstrcpy(si->requiredstop,""); - pstrcpy(si->description,""); - pstrcpy(si->shortdescription,""); - - numlines = &nlines; - in_section = 0; - in_description = 0; - - - if( !fname || !*fname ) { - DEBUG(0, ("Must define an \"LSB-style init file\" to read.\n")); - return False; - } - pstrcpy(initdfile,dyn_LIBDIR); - pstrcat(initdfile,SVCCTL_SCRIPT_DIR); - pstrcat(initdfile,fname); - - /* TODO - should check to see if the file that we're trying to open is - actually a script. If it's NOT, we should do something like warn, - and not continue to try to find info we're looking for */ - - DEBUG(10, ("Opening [%s]\n", initdfile)); - fd = -1; - fd = open(initdfile,O_RDONLY); - *numlines = 0; - - if (fd == -1) { - DEBUG(10, ("Couldn't open [%s]\n", initdfile)); - return False; - } - - qlines = fd_lines_load(fd, numlines); - DEBUGADD(10, ("Lines returned = [%d]\n", *numlines)); - close(fd); - - - if (*numlines) { - - for(i = 0; i < *numlines; i++) { - - DEBUGADD(10, ("Line[%d] = %s\n", i, qlines[i])); - if (!in_section && (0==strwicmp("### BEGIN INIT INFO", qlines[i]))) { - /* we now can look for params */ - DEBUGADD(10, ("Configuration information starts on line = [%d]\n", i)); - in_section = 1; - - } else if (in_section && (0==strwicmp("### END INIT INFO", qlines[i]))) { - DEBUGADD(10, ("Configuration information ends on line = [%d]\n", i)); - DEBUGADD(10, ("Description is [%s]\n", si->description)); - in_description = 0; - in_section = 0; - break; - } else if (in_section) { - tokenptr = qlines[i]; - if (in_description) { - DEBUGADD(10, ("Processing DESCRIPTION [%d]\n", *tokenptr)); - if (tokenptr && (*tokenptr=='#') && (*(tokenptr+1)=='\t')) { - DEBUGADD(10, ("Adding to DESCRIPTION [%d]\n", *tokenptr)); - pstrcat(si->description," "); - pstrcat(si->description,tokenptr+2); - continue; - } - in_description = 0; - DEBUGADD(10, ("Not a description!\n")); - } - if (!next_token(&tokenptr,mybuffer," \t",sizeof(mybuffer))) { - DEBUGADD(10, ("Invalid line [%d]\n", i)); - break; /* bad line? */ - } - if (0 != strncmp(mybuffer,"#",1)) { - DEBUGADD(10, ("Invalid line [%d], is %s\n", i,mybuffer)); - break; - } - if (!next_token(&tokenptr,mybuffer," \t",sizeof(mybuffer))) { - DEBUGADD(10, ("Invalid token on line [%d]\n", i)); - break; /* bad line? */ - } - DEBUGADD(10, ("Keyword is [%s]\n", mybuffer)); - if (0==strwicmp(mybuffer,"Description:")) { - while (tokenptr && *tokenptr && (strchr(" \t",*tokenptr))) { - tokenptr++; - } - pstrcpy(si->description,tokenptr); - DEBUGADD(10, ("FOUND DESCRIPTION! Data is [%s]\n", tokenptr)); - in_description = 1; - } else { - while (tokenptr && *tokenptr && (strchr(" \t",*tokenptr))) { - tokenptr++; - } - DEBUGADD(10, ("Data is [%s]\n", tokenptr)); - in_description = 0; - - /* save certain keywords, don't save others */ - if (0==strwicmp(mybuffer, "Provides:")) { - pstrcpy(si->provides,tokenptr); - pstrcpy(si->servicename,tokenptr); - } - - if (0==strwicmp(mybuffer, "Short-Description:")) { - pstrcpy(si->shortdescription,tokenptr); - } - - if (0==strwicmp(mybuffer, "Required-start:")) { - pstrcpy(si->requiredstart,tokenptr); - pstrcpy(si->dependencies,tokenptr); - } - - if (0==strwicmp(mybuffer, "Should-start:")) { - pstrcpy(si->shouldstart,tokenptr); - } - } - } - } - - file_lines_free(qlines); - return True; - } - - return False; -} - /********************************************************************* *********************************************************************/ diff --git a/source3/services/svc_wins.c b/source3/services/svc_wins.c new file mode 100644 index 0000000000..3a4650664d --- /dev/null +++ b/source3/services/svc_wins.c @@ -0,0 +1,66 @@ +/* + * Unix SMB/CIFS implementation. + * Service Control API Implementation + * Copyright (C) Gerald Carter 2005. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* Implementation for internal wins service */ + +/********************************************************************* +*********************************************************************/ + +static WERROR wins_stop( const char *service, SERVICE_STATUS *service_status ) +{ + return WERR_ACCESS_DENIED; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR wins_start( const char *service ) +{ + return WERR_ACCESS_DENIED; +} + +/********************************************************************* +*********************************************************************/ + +static WERROR wins_status( const char *service, SERVICE_STATUS *service_status ) +{ + ZERO_STRUCTP( service_status ); + + service_status->type = 0x10; + if ( lp_wins_support() ) + service_status->state = SVCCTL_RUNNING; + else + service_status->state = SVCCTL_STOPPED; + + return WERR_OK; +} + +/********************************************************************* +*********************************************************************/ + +/* struct for svcctl control to manipulate wins service */ + +SERVICE_CONTROL_OPS wins_svc_ops = { + wins_stop, + wins_start, + wins_status +}; -- cgit From 01a1e5cdb0339a7cb3a85280b118985562bb2d7f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 7 Oct 2005 12:14:25 +0000 Subject: r10819: merging a couple of fixes from trunk * only keep the registry,tdb file open when we have an open key handle * tpot's setup.py fix * removing files that no longer exist in trunk and copying some that were missing in 3.0 (This used to be commit 6c6bf6ca5fd430a7a20bf20ed08050328660e570) --- source3/services/services_db.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 7c75d41352..e1b2f88865 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -325,6 +325,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, if ( !(svc_subkeys = TALLOC_ZERO_P( key_service, REGSUBKEY_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + regkey_close_internal( key_service ); return; } @@ -336,6 +337,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, if ( !(values = TALLOC_ZERO_P( key_service, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + regkey_close_internal( key_service ); return; } @@ -344,7 +346,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* cleanup the service key*/ - TALLOC_FREE( key_service ); + regkey_close_internal( key_service ); /* now add the security descriptor */ @@ -354,17 +356,19 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); + regkey_close_internal( key_secdesc ); return; } if ( !(values = TALLOC_ZERO_P( key_secdesc, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + regkey_close_internal( key_secdesc ); return; } if ( !(sd = construct_service_sd(key_secdesc)) ) { DEBUG(0,("add_new_svc_name: Failed to create default sec_desc!\n")); - TALLOC_FREE( key_secdesc ); + regkey_close_internal( key_secdesc ); return; } @@ -381,7 +385,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* finally cleanup the Security key */ prs_mem_free( &ps ); - TALLOC_FREE( key_secdesc ); + regkey_close_internal( key_secdesc ); return; } @@ -413,6 +417,7 @@ void svcctl_init_keys( void ) if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) { DEBUG(0,("init_services_keys: talloc() failed!\n")); + regkey_close_internal( key ); return; } @@ -436,7 +441,7 @@ void svcctl_init_keys( void ) new_services = True; } - TALLOC_FREE( key ); + regkey_close_internal( key ); /* initialize the control hooks */ @@ -474,7 +479,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); - TALLOC_FREE( key ); + regkey_close_internal( key ); return NULL; } @@ -483,7 +488,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * if ( !(val = regval_ctr_getvalue( values, "Security" )) ) { DEBUG(6,("svcctl_get_secdesc: constructing default secdesc for service [%s]\n", name)); - TALLOC_FREE( key ); + regkey_close_internal( key ); return construct_service_sd( ctx ); } @@ -494,7 +499,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * prs_give_memory( &ps, regval_data_p(val), regval_size(val), False ); if ( !sec_io_desc("sec_desc", &sd, &ps, 0 ) ) { - TALLOC_FREE( key ); + regkey_close_internal( key ); return construct_service_sd( ctx ); } @@ -503,7 +508,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * /* finally cleanup the Security key */ prs_mem_free( &ps ); - TALLOC_FREE( key ); + regkey_close_internal( key ); return ret_sd; } @@ -532,7 +537,7 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n")); - TALLOC_FREE( key ); + regkey_close_internal( key ); goto fail; } @@ -543,12 +548,13 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) rpcstr_pull( display_name, regval_data_p(val), sizeof(display_name), regval_size(val), 0 ); - TALLOC_FREE( key ); + regkey_close_internal( key ); return display_name; fail: /* default to returning the service name */ + regkey_close_internal( key ); fstrcpy( display_name, name ); return display_name; } @@ -577,7 +583,7 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n")); - TALLOC_FREE( key ); + regkey_close_internal( key ); return NULL; } @@ -588,7 +594,7 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) else rpcstr_pull( description, regval_data_p(val), sizeof(description), regval_size(val), 0 ); - TALLOC_FREE( key ); + regkey_close_internal( key ); return description; } @@ -616,13 +622,13 @@ REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token ) if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) { DEBUG(0,("svcctl_fetch_regvalues: talloc() failed!\n")); - TALLOC_FREE( key ); + regkey_close_internal( key ); return NULL; } fetch_reg_values( key, values ); - TALLOC_FREE( key ); + regkey_close_internal( key ); return values; } -- cgit From de0776cdaa3e4c5fab9fe7adfd5fdb3e7b2b1659 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 13 Oct 2005 13:20:26 +0000 Subject: r10961: remove unused variables (patch from Jason Mader) (This used to be commit d6c6562d33cc88827cb8560a412e8ea51f9a5352) --- source3/services/services_db.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index e1b2f88865..9cd9ba8d83 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -175,7 +175,7 @@ static BOOL read_init_file( const char *servicename, struct rcinit_file_informat struct rcinit_file_information *info; pstring filepath, str; XFILE *f; - char *p, *s; + char *p; if ( !(info = TALLOC_ZERO_P( NULL, struct rcinit_file_information ) ) ) return False; @@ -189,7 +189,7 @@ static BOOL read_init_file( const char *servicename, struct rcinit_file_informat return False; } - while ( (s = x_fgets( str, sizeof(str)-1, f )) != NULL ) { + while ( (x_fgets( str, sizeof(str)-1, f )) != NULL ) { /* ignore everything that is not a full line comment starting with a '#' */ @@ -400,7 +400,6 @@ void svcctl_init_keys( void ) REGSUBKEY_CTR *subkeys; REGISTRY_KEY *key = NULL; WERROR wresult; - BOOL new_services = False; /* bad mojo here if the lookup failed. Should not happen */ @@ -437,8 +436,6 @@ void svcctl_init_keys( void ) /* Add the new service key and initialize the appropriate values */ add_new_svc_name( key, subkeys, service_list[i] ); - - new_services = True; } regkey_close_internal( key ); -- cgit From 8d7c88667190fe286971ac4fffb64ee5bd9eeeb0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Oct 2005 03:24:00 +0000 Subject: r11137: Compile with only 2 warnings (I'm still working on that code) on a gcc4 x86_64 box. Jeremy. (This used to be commit d720867a788c735e56d53d63265255830ec21208) --- source3/services/services_db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 9cd9ba8d83..477bf4e269 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -493,7 +493,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * /* stream the printer security descriptor */ prs_init( &ps, 0, key, UNMARSHALL); - prs_give_memory( &ps, regval_data_p(val), regval_size(val), False ); + prs_give_memory( &ps, (char *)regval_data_p(val), regval_size(val), False ); if ( !sec_io_desc("sec_desc", &sd, &ps, 0 ) ) { regkey_close_internal( key ); -- cgit From 77460a90756dcaa54ec12bbcd30a5266286103d7 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 8 Nov 2005 16:33:45 +0000 Subject: r11579: syncing up perf counter code cfrom trunk (This used to be commit 59c00924b67aa3d37a933731a56d03963ec7f1b5) --- source3/services/services_db.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 477bf4e269..5c87225f57 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -71,6 +71,7 @@ struct service_display_info common_unix_svcs[] = { { "apache", NULL, "HTTP Server", NULL }, { "autofs", NULL, "Automounter", NULL }, { "squid", NULL, "Web Cache Proxy ", NULL }, + { "perfcountd", NULL, "Performance Monitoring Daemon", NULL }, { NULL, NULL, NULL, NULL } }; -- cgit From 65540512df2a0072b88c63195a61b0ab8054cf8a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 21 Nov 2005 13:00:36 +0000 Subject: r11830: patch from Rashid N. Achilov to add descriptions for some common services (This used to be commit 69e168197e576bac6d4b29bdca876243eb7caf68) --- source3/services/services_db.c | 72 +++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 32 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 5c87225f57..c75cb38c48 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -35,43 +35,51 @@ struct service_display_info { }; struct service_display_info builtin_svcs[] = { - { "Spooler", "smbd", "Print Spooler", - "Internal service for spooling files to print devices" }, - { "NETLOGON", "smbd", "Net Logon", - "File service providing access to policy and profile data" }, - { "RemoteRegistry", "smbd", "Remote Registry Service", - "Internal service providing remote access to the Samba registry" }, - { "WINS", "nmbd", "Windows Internet Name Service (WINS)", - "Internal service providing a NetBIOS point-to-point name server" }, + { "Spooler", "smbd", "Print Spooler", "Internal service for spooling files to print devices" }, + { "NETLOGON", "smbd", "Net Logon", "File service providing access to policy and profile data" }, + { "RemoteRegistry", "smbd", "Remote Registry Service", "Internal service providing remote access to " + "the Samba registry" }, + { "WINS", "nmbd", "Windows Internet Name Service (WINS)", "Internal service providing a " + "NetBIOS point-to-point name server" }, { NULL, NULL, NULL, NULL } }; struct service_display_info common_unix_svcs[] = { - { "cups", NULL, "Common Unix Printing System", NULL }, - { "postfix", NULL, "Internet Mail Service", NULL }, - { "sendmail", NULL, "Internet Mail Service", NULL }, - { "portmap", NULL, "TCP Port to RPC PortMapper", NULL }, - { "xinetd", NULL, "Internet Meta-Daemon", NULL }, - { "inet", NULL, "Internet Meta-Daemon", NULL }, - { "xntpd", NULL, "Network Time Service", NULL }, - { "ntpd", NULL, "Network Time Service", NULL }, - { "lpd", NULL, "BSD Print Spooler", NULL }, - { "nfsserver", NULL, "Network File Service", NULL }, - { "cron", NULL, "Scheduling Service", NULL }, - { "at", NULL, "Scheduling Service", NULL }, - { "nscd", NULL, "Name Service Cache Daemon", NULL }, - { "slapd", NULL, "LDAP Directory Service", NULL }, - { "ldap", NULL, "LDAP DIrectory Service", NULL }, - { "ypbind", NULL, "NIS Directory Service", NULL }, - { "courier-imap", NULL, "IMAP4 Mail Service", NULL }, - { "courier-pop3", NULL, "POP3 Mail Service", NULL }, - { "named", NULL, "Domain Name Service", NULL }, - { "bind", NULL, "Domain Name Service", NULL }, - { "httpd", NULL, "HTTP Server", NULL }, - { "apache", NULL, "HTTP Server", NULL }, - { "autofs", NULL, "Automounter", NULL }, - { "squid", NULL, "Web Cache Proxy ", NULL }, + { "cups", NULL, "Common Unix Printing System","Provides unified printing support for all operating systems" }, + { "postfix", NULL, "Internet Mail Service", "Provides support for sending and receiving electonic mail" }, + { "sendmail", NULL, "Internet Mail Service", "Provides support for sending and receiving electonic mail" }, + { "portmap", NULL, "TCP Port to RPC PortMapper",NULL }, + { "xinetd", NULL, "Internet Meta-Daemon", NULL }, + { "inet", NULL, "Internet Meta-Daemon", NULL }, + { "xntpd", NULL, "Network Time Service", NULL }, + { "ntpd", NULL, "Network Time Service", NULL }, + { "lpd", NULL, "BSD Print Spooler", NULL }, + { "nfsserver", NULL, "Network File Service", NULL }, + { "cron", NULL, "Scheduling Service", NULL }, + { "at", NULL, "Scheduling Service", NULL }, + { "nscd", NULL, "Name Service Cache Daemon", NULL }, + { "slapd", NULL, "LDAP Directory Service", NULL }, + { "ldap", NULL, "LDAP DIrectory Service", NULL }, + { "ypbind", NULL, "NIS Directory Service", NULL }, + { "courier-imap", NULL, "IMAP4 Mail Service", NULL }, + { "courier-pop3", NULL, "POP3 Mail Service", NULL }, + { "named", NULL, "Domain Name Service", NULL }, + { "bind", NULL, "Domain Name Service", NULL }, + { "httpd", NULL, "HTTP Server", NULL }, + { "apache", NULL, "HTTP Server", "Provides s highly scalable and flexible web server " + "capable of implementing various protocols incluing " + "but not limited to HTTP" }, + { "autofs", NULL, "Automounter", NULL }, + { "squid", NULL, "Web Cache Proxy ", NULL }, { "perfcountd", NULL, "Performance Monitoring Daemon", NULL }, + { "pgsql", NULL, "PgSQL Database Server", "Provides service for SQL database from Postgresql.org" }, + { "arpwatch", NULL, "ARP Tables watcher", "Provides service for monitoring ARP tables for changes" }, + { "dhcpd", NULL, "DHCP Server", "Provides service for dynamic host configuration and IP assignment" }, + { "nwserv", NULL, "NetWare Server Emulator", "Provides service for emulating Novell NetWare 3.12 server" }, + { "proftpd", NULL, "Professional FTP Server", "Provides high configurable service for FTP connection and " + "file transferring" }, + { "ssh2", NULL, "SSH Secure Shell", "Provides service for secure connection for remote administration" }, + { "sshd", NULL, "SSH Secure Shell", "Provides service for secure connection for remote administration" }, { NULL, NULL, NULL, NULL } }; -- cgit From a48955306705ac7f045e3726d7097900550bebe3 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 11 Dec 2005 04:21:34 +0000 Subject: r12173: doing some service control work * Add a few new error codes for disabled services * dump some more details about service status in 'net rpc service' * disable the WINS and NetLogon services if not configured in smb.conf Still trying to figure out how to disable the start button on the NetLogon and WINS services. (This used to be commit c0f54eeebc84ec9fab63c5b105511762bcc136be) --- source3/services/svc_netlogon.c | 33 +++++++++++++++++++++------------ source3/services/svc_wins.c | 32 +++++++++++++++++++------------- 2 files changed, 40 insertions(+), 25 deletions(-) (limited to 'source3/services') diff --git a/source3/services/svc_netlogon.c b/source3/services/svc_netlogon.c index 2aa5a31cde..1bbef325ac 100644 --- a/source3/services/svc_netlogon.c +++ b/source3/services/svc_netlogon.c @@ -25,33 +25,42 @@ /********************************************************************* *********************************************************************/ -static WERROR netlogon_stop( const char *service, SERVICE_STATUS *service_status ) +static WERROR netlogon_status( const char *service, SERVICE_STATUS *service_status ) { - return WERR_ACCESS_DENIED; + ZERO_STRUCTP( service_status ); + + service_status->type = 0x20; + service_status->controls_accepted = SVCCTL_ACCEPT_NONE; + + if ( lp_servicenumber("NETLOGON") != -1 ) { + service_status->state = SVCCTL_RUNNING; + service_status->win32_exit_code = WERR_SERVICE_NEVER_STARTED; + } + else + service_status->state = SVCCTL_STOPPED; + + return WERR_OK; } /********************************************************************* *********************************************************************/ -static WERROR netlogon_start( const char *service ) +static WERROR netlogon_stop( const char *service, SERVICE_STATUS *service_status ) { + netlogon_status( service, service_status ); + return WERR_ACCESS_DENIED; } /********************************************************************* *********************************************************************/ -static WERROR netlogon_status( const char *service, SERVICE_STATUS *service_status ) +static WERROR netlogon_start( const char *service ) { - ZERO_STRUCTP( service_status ); + if ( lp_servicenumber("NETLOGON") == -1 ) + return WERR_SERVICE_DISABLED; - service_status->type = 0x20; - if ( lp_servicenumber("NETLOGON") != -1 ) - service_status->state = SVCCTL_RUNNING; - else - service_status->state = SVCCTL_STOPPED; - - return WERR_OK; + return WERR_ACCESS_DENIED; } /********************************************************************* diff --git a/source3/services/svc_wins.c b/source3/services/svc_wins.c index 3a4650664d..37cfc99c06 100644 --- a/source3/services/svc_wins.c +++ b/source3/services/svc_wins.c @@ -25,33 +25,39 @@ /********************************************************************* *********************************************************************/ -static WERROR wins_stop( const char *service, SERVICE_STATUS *service_status ) +static WERROR wins_status( const char *service, SERVICE_STATUS *service_status ) { - return WERR_ACCESS_DENIED; + ZERO_STRUCTP( service_status ); + + service_status->type = 0x10; + service_status->controls_accepted = SVCCTL_ACCEPT_NONE; + + if ( lp_wins_support() ) + service_status->state = SVCCTL_RUNNING; + else { + service_status->state = SVCCTL_STOPPED; + service_status->win32_exit_code = WERR_SERVICE_NEVER_STARTED; + } + + return WERR_OK; } /********************************************************************* *********************************************************************/ -static WERROR wins_start( const char *service ) +static WERROR wins_stop( const char *service, SERVICE_STATUS *service_status ) { + wins_status( service, service_status ); + return WERR_ACCESS_DENIED; } /********************************************************************* *********************************************************************/ -static WERROR wins_status( const char *service, SERVICE_STATUS *service_status ) +static WERROR wins_start( const char *service ) { - ZERO_STRUCTP( service_status ); - - service_status->type = 0x10; - if ( lp_wins_support() ) - service_status->state = SVCCTL_RUNNING; - else - service_status->state = SVCCTL_STOPPED; - - return WERR_OK; + return WERR_ACCESS_DENIED; } /********************************************************************* -- cgit From 31c73b99136a55a0311213513d2ec161fac15190 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 16 Dec 2005 01:41:25 +0000 Subject: r12281: adding a note about WINS and NetLogon not being remotely manageable (This used to be commit b86528865abae7380e80a8a18f9fb53ac77d6472) --- source3/services/services_db.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index c75cb38c48..b3ba7fcc96 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -36,11 +36,11 @@ struct service_display_info { struct service_display_info builtin_svcs[] = { { "Spooler", "smbd", "Print Spooler", "Internal service for spooling files to print devices" }, - { "NETLOGON", "smbd", "Net Logon", "File service providing access to policy and profile data" }, + { "NETLOGON", "smbd", "Net Logon", "File service providing access to policy and profile data (not remotely manageable)" }, { "RemoteRegistry", "smbd", "Remote Registry Service", "Internal service providing remote access to " "the Samba registry" }, { "WINS", "nmbd", "Windows Internet Name Service (WINS)", "Internal service providing a " - "NetBIOS point-to-point name server" }, + "NetBIOS point-to-point name server (not remotely manageable)" }, { NULL, NULL, NULL, NULL } }; -- cgit From e7a1a0ead2013464dc8204e5b997ddc3ae46e973 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 13 Jan 2006 20:24:50 +0000 Subject: r12914: adding query/set ops for security descriptors on services. (This used to be commit cefd2d7cb6140b068d66e2383e9acfa4c3c4b4c7) --- source3/services/services_db.c | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index b3ba7fcc96..a16657c0ed 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -519,6 +519,53 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * return ret_sd; } +/******************************************************************** + Wrapper to make storing a Service sd easier +********************************************************************/ + +BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, NT_USER_TOKEN *token ) +{ + REGISTRY_KEY *key; + WERROR wresult; + pstring path; + REGVAL_CTR *values; + prs_struct ps; + BOOL ret = False; + + /* now add the security descriptor */ + + pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + if ( !W_ERROR_IS_OK(wresult) ) { + DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", + path, dos_errstr(wresult))); + return False; + } + + if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { + DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + regkey_close_internal( key ); + return False; + } + + /* stream the printer security descriptor */ + + prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key, MARSHALL); + + if ( sec_io_desc("sec_desc", &sec_desc, &ps, 0 ) ) { + uint32 offset = prs_offset( &ps ); + regval_ctr_addvalue( values, "Security", REG_BINARY, prs_data_p(&ps), offset ); + ret = store_reg_values( key, values ); + } + + /* cleanup */ + + prs_mem_free( &ps ); + regkey_close_internal( key); + + return ret; +} + /******************************************************************** ********************************************************************/ -- cgit From ef3f2c9675194efa17cfd4b4b5393a6e0a335bdf Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 8 Feb 2006 15:09:09 +0000 Subject: r13393: Do not initialize the lp_svcctl_list() value since it is handled internally in services_db.c now. This prevents internal services from being listed twice (one internal and one external) when no 'svcctl list' parameter is explcitly set in smb.conf (This used to be commit 6c4ede6cee7e1d25a6357e959972e8d390c27fe3) --- source3/services/services_db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index a16657c0ed..6c38c6ed0a 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -436,7 +436,7 @@ void svcctl_init_keys( void ) for ( i=0; builtin_svcs[i].servicename; i++ ) add_new_svc_name( key, subkeys, builtin_svcs[i].servicename ); - for ( i=0; service_list[i]; i++ ) { + for ( i=0; service_list && service_list[i]; i++ ) { /* only add new services */ if ( regsubkey_ctr_key_exists( subkeys, service_list[i] ) ) -- cgit From 58e00365c6b36454ab1c4d6409a5094a6de154f2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 10 Mar 2006 08:53:15 +0000 Subject: r14132: Fix Coverity bug # 150. Jerry, you might want to check this. Thanks Volker (This used to be commit 9ec671c2f8547482ed08eb17a0fb771ef8fd1e51) --- source3/services/services_db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 6c38c6ed0a..5b4f58d766 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -160,7 +160,7 @@ static char* cleanup_string( const char *string ) while ( isspace(*begin) ) begin++; - if ( !begin ) + if ( *begin == '\0' ) return NULL; /* trim any trailing whitespace or carriage returns. -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/services/svc_netlogon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/services') diff --git a/source3/services/svc_netlogon.c b/source3/services/svc_netlogon.c index 1bbef325ac..c561870552 100644 --- a/source3/services/svc_netlogon.c +++ b/source3/services/svc_netlogon.c @@ -32,7 +32,7 @@ static WERROR netlogon_status( const char *service, SERVICE_STATUS *service_stat service_status->type = 0x20; service_status->controls_accepted = SVCCTL_ACCEPT_NONE; - if ( lp_servicenumber("NETLOGON") != -1 ) { + if ( share_defined("NETLOGON") ) { service_status->state = SVCCTL_RUNNING; service_status->win32_exit_code = WERR_SERVICE_NEVER_STARTED; } @@ -57,7 +57,7 @@ static WERROR netlogon_stop( const char *service, SERVICE_STATUS *service_status static WERROR netlogon_start( const char *service ) { - if ( lp_servicenumber("NETLOGON") == -1 ) + if ( share_defined("NETLOGON") ) return WERR_SERVICE_DISABLED; return WERR_ACCESS_DENIED; -- cgit From bdfeaf2bcfe2bf79a693f5381e3cb9c26833bb72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 19 Jul 2006 20:54:39 +0000 Subject: r17148: the wins service should not accept any controls so that a GUI can grey it out as not remotely manageable (This used to be commit 859c51cf25a2bb80787a5060156f09c2f0142dfb) --- source3/services/svc_winreg.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/services') diff --git a/source3/services/svc_winreg.c b/source3/services/svc_winreg.c index 1bccee246e..8fa49d3c3b 100644 --- a/source3/services/svc_winreg.c +++ b/source3/services/svc_winreg.c @@ -46,6 +46,7 @@ static WERROR winreg_status( const char *service, SERVICE_STATUS *service_status ZERO_STRUCTP( service_status ); service_status->type = 0x20; + service_status->controls_accepted = SVCCTL_ACCEPT_NONE; service_status->state = SVCCTL_RUNNING; return WERR_OK; -- cgit From e82cd437cc3c93e25f56d3326d6ba527a33ebfbf Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Nov 2006 10:50:33 +0000 Subject: r19778: Make regkey_open_internal take a talloc ctx (This used to be commit cb7f4211b8441642dce9594522dc9588475a7719) --- source3/services/services_db.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 5b4f58d766..7573d3ba2d 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -322,8 +322,8 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* open the new service key */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key_service, path, get_root_nt_token(), - REG_KEY_ALL ); + wresult = regkey_open_internal( NULL, &key_service, path, + get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -360,8 +360,8 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( &key_secdesc, path, get_root_nt_token(), - REG_KEY_ALL ); + wresult = regkey_open_internal( NULL, &key_secdesc, path, + get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -412,8 +412,8 @@ void svcctl_init_keys( void ) /* bad mojo here if the lookup failed. Should not happen */ - wresult = regkey_open_internal( &key, KEY_SERVICES, get_root_nt_token(), - REG_KEY_ALL ); + wresult = regkey_open_internal( NULL, &key, KEY_SERVICES, + get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("init_services_keys: key lookup failed! (%s)\n", @@ -476,7 +476,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -535,7 +535,7 @@ BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -581,7 +581,8 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); + wresult = regkey_open_internal( NULL, &key, path, token, + REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -627,7 +628,8 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); + wresult = regkey_open_internal( NULL, &key, path, token, + REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -666,7 +668,8 @@ REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); + wresult = regkey_open_internal( NULL, &key, path, token, + REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); -- cgit From bfad4421449d7f49287b1ebe81bf572c271f8fca Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Nov 2006 11:11:01 +0000 Subject: r19780: Ok, regkey_open_internal needs a regkey_close_internal. Giving a talloc ctx is misleading here. This needs fixing properly :-) Volker (This used to be commit f808182346aa16bb2f3a9383e28d318099a5e14e) --- source3/services/services_db.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 7573d3ba2d..5b4f58d766 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -322,8 +322,8 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* open the new service key */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( NULL, &key_service, path, - get_root_nt_token(), REG_KEY_ALL ); + wresult = regkey_open_internal( &key_service, path, get_root_nt_token(), + REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -360,8 +360,8 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( NULL, &key_secdesc, path, - get_root_nt_token(), REG_KEY_ALL ); + wresult = regkey_open_internal( &key_secdesc, path, get_root_nt_token(), + REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -412,8 +412,8 @@ void svcctl_init_keys( void ) /* bad mojo here if the lookup failed. Should not happen */ - wresult = regkey_open_internal( NULL, &key, KEY_SERVICES, - get_root_nt_token(), REG_KEY_ALL ); + wresult = regkey_open_internal( &key, KEY_SERVICES, get_root_nt_token(), + REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("init_services_keys: key lookup failed! (%s)\n", @@ -476,7 +476,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_ALL ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -535,7 +535,7 @@ BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_ALL ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -581,8 +581,7 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( NULL, &key, path, token, - REG_KEY_READ ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -628,8 +627,7 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( NULL, &key, path, token, - REG_KEY_READ ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -668,8 +666,7 @@ REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( NULL, &key, path, token, - REG_KEY_READ ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); -- cgit From 1c91cca86eacc74c2785c54bc75c5ff18d7a773d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 29 Nov 2006 10:51:00 +0000 Subject: r19947: Change regkey_open_internal to take the parent key and a talloc_ctx as arguments. This also replaces regkey_close_internal by TALLOC_FREE. Volker (This used to be commit a177bbb2d5611f03cec25b7577c2e6a542f94a69) --- source3/services/services_db.c | 71 ++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 33 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 5b4f58d766..40022ab365 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -322,8 +322,8 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* open the new service key */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key_service, path, get_root_nt_token(), - REG_KEY_ALL ); + wresult = regkey_open_internal( NULL, NULL, &key_service, path, + get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -334,7 +334,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, if ( !(svc_subkeys = TALLOC_ZERO_P( key_service, REGSUBKEY_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); - regkey_close_internal( key_service ); + TALLOC_FREE( key_service ); return; } @@ -346,7 +346,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, if ( !(values = TALLOC_ZERO_P( key_service, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); - regkey_close_internal( key_service ); + TALLOC_FREE( key_service ); return; } @@ -355,29 +355,29 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* cleanup the service key*/ - regkey_close_internal( key_service ); + TALLOC_FREE( key_service ); /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( &key_secdesc, path, get_root_nt_token(), - REG_KEY_ALL ); + wresult = regkey_open_internal( NULL, NULL, &key_secdesc, path, + get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); - regkey_close_internal( key_secdesc ); + TALLOC_FREE( key_secdesc ); return; } if ( !(values = TALLOC_ZERO_P( key_secdesc, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); - regkey_close_internal( key_secdesc ); + TALLOC_FREE( key_secdesc ); return; } if ( !(sd = construct_service_sd(key_secdesc)) ) { DEBUG(0,("add_new_svc_name: Failed to create default sec_desc!\n")); - regkey_close_internal( key_secdesc ); + TALLOC_FREE( key_secdesc ); return; } @@ -394,7 +394,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* finally cleanup the Security key */ prs_mem_free( &ps ); - regkey_close_internal( key_secdesc ); + TALLOC_FREE( key_secdesc ); return; } @@ -412,8 +412,8 @@ void svcctl_init_keys( void ) /* bad mojo here if the lookup failed. Should not happen */ - wresult = regkey_open_internal( &key, KEY_SERVICES, get_root_nt_token(), - REG_KEY_ALL ); + wresult = regkey_open_internal( NULL, NULL, &key, KEY_SERVICES, + get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("init_services_keys: key lookup failed! (%s)\n", @@ -425,7 +425,7 @@ void svcctl_init_keys( void ) if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) { DEBUG(0,("init_services_keys: talloc() failed!\n")); - regkey_close_internal( key ); + TALLOC_FREE( key ); return; } @@ -447,7 +447,7 @@ void svcctl_init_keys( void ) add_new_svc_name( key, subkeys, service_list[i] ); } - regkey_close_internal( key ); + TALLOC_FREE( key ); /* initialize the control hooks */ @@ -476,7 +476,8 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + wresult = regkey_open_internal( NULL, NULL, &key, path, token, + REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -485,7 +486,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); - regkey_close_internal( key ); + TALLOC_FREE( key ); return NULL; } @@ -494,7 +495,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * if ( !(val = regval_ctr_getvalue( values, "Security" )) ) { DEBUG(6,("svcctl_get_secdesc: constructing default secdesc for service [%s]\n", name)); - regkey_close_internal( key ); + TALLOC_FREE( key ); return construct_service_sd( ctx ); } @@ -505,7 +506,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * prs_give_memory( &ps, (char *)regval_data_p(val), regval_size(val), False ); if ( !sec_io_desc("sec_desc", &sd, &ps, 0 ) ) { - regkey_close_internal( key ); + TALLOC_FREE( key ); return construct_service_sd( ctx ); } @@ -514,7 +515,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * /* finally cleanup the Security key */ prs_mem_free( &ps ); - regkey_close_internal( key ); + TALLOC_FREE( key ); return ret_sd; } @@ -535,7 +536,8 @@ BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + wresult = regkey_open_internal( NULL, NULL, &key, path, token, + REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -544,7 +546,7 @@ BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); - regkey_close_internal( key ); + TALLOC_FREE( key ); return False; } @@ -561,7 +563,7 @@ BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, /* cleanup */ prs_mem_free( &ps ); - regkey_close_internal( key); + TALLOC_FREE( key); return ret; } @@ -581,7 +583,8 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); + wresult = regkey_open_internal( NULL, NULL, &key, path, token, + REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -590,7 +593,7 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n")); - regkey_close_internal( key ); + TALLOC_FREE( key ); goto fail; } @@ -601,13 +604,13 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) rpcstr_pull( display_name, regval_data_p(val), sizeof(display_name), regval_size(val), 0 ); - regkey_close_internal( key ); + TALLOC_FREE( key ); return display_name; fail: /* default to returning the service name */ - regkey_close_internal( key ); + TALLOC_FREE( key ); fstrcpy( display_name, name ); return display_name; } @@ -627,7 +630,8 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); + wresult = regkey_open_internal( NULL, NULL, &key, path, token, + REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -636,7 +640,7 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n")); - regkey_close_internal( key ); + TALLOC_FREE( key ); return NULL; } @@ -647,7 +651,7 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) else rpcstr_pull( description, regval_data_p(val), sizeof(description), regval_size(val), 0 ); - regkey_close_internal( key ); + TALLOC_FREE( key ); return description; } @@ -666,7 +670,8 @@ REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( &key, path, token, REG_KEY_READ ); + wresult = regkey_open_internal( NULL, NULL, &key, path, token, + REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); @@ -675,13 +680,13 @@ REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token ) if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) { DEBUG(0,("svcctl_fetch_regvalues: talloc() failed!\n")); - regkey_close_internal( key ); + TALLOC_FREE( key ); return NULL; } fetch_reg_values( key, values ); - regkey_close_internal( key ); + TALLOC_FREE( key ); return values; } -- cgit From ecf90c495eb850cd6f376fb4e090640b69f0c029 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 1 Dec 2006 20:01:09 +0000 Subject: r19991: Sorry for this 2000-liner... The main thing here is a rewrite of srv_winreg_nt.c. The core functionality has moved to registry/reg_api.c which is then usable by the rest of Samba as well. On that way it fixes creating keys with more than one element in the path. This did not work before. Two things that sneaked in (sorry :-) is the change of some routines from NTSTATUS to WERROR the removed "parent" argument to regkey_open_internal. Volker (This used to be commit fea52801de8c7b85c578d200c599475680c5339f) --- source3/services/services_db.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 40022ab365..c9e172da2a 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -322,7 +322,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* open the new service key */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( NULL, NULL, &key_service, path, + wresult = regkey_open_internal( NULL, &key_service, path, get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", @@ -360,7 +360,7 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( NULL, NULL, &key_secdesc, path, + wresult = regkey_open_internal( NULL, &key_secdesc, path, get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", @@ -412,7 +412,7 @@ void svcctl_init_keys( void ) /* bad mojo here if the lookup failed. Should not happen */ - wresult = regkey_open_internal( NULL, NULL, &key, KEY_SERVICES, + wresult = regkey_open_internal( NULL, &key, KEY_SERVICES, get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { @@ -476,7 +476,7 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( NULL, NULL, &key, path, token, + wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", @@ -536,7 +536,7 @@ BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); - wresult = regkey_open_internal( NULL, NULL, &key, path, token, + wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", @@ -583,7 +583,7 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( NULL, NULL, &key, path, token, + wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", @@ -630,7 +630,7 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( NULL, NULL, &key, path, token, + wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", @@ -670,7 +670,7 @@ REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token ) /* now add the security descriptor */ pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); - wresult = regkey_open_internal( NULL, NULL, &key, path, token, + wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n", -- cgit From ff61853fb35953f7e4f210ce3e5a82e6da15534e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 7 Dec 2006 19:21:37 +0000 Subject: r20069: Fix logic bug I introduced (This used to be commit d935ecec98747dfd9f35ab81760ef95a0d983ed7) --- source3/services/svc_netlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/services') diff --git a/source3/services/svc_netlogon.c b/source3/services/svc_netlogon.c index c561870552..09e841cf7e 100644 --- a/source3/services/svc_netlogon.c +++ b/source3/services/svc_netlogon.c @@ -57,7 +57,7 @@ static WERROR netlogon_stop( const char *service, SERVICE_STATUS *service_status static WERROR netlogon_start( const char *service ) { - if ( share_defined("NETLOGON") ) + if ( !share_defined("NETLOGON") ) return WERR_SERVICE_DISABLED; return WERR_ACCESS_DENIED; -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/services/services_db.c | 2 +- source3/services/svc_netlogon.c | 2 +- source3/services/svc_rcinit.c | 2 +- source3/services/svc_spoolss.c | 2 +- source3/services/svc_winreg.c | 2 +- source3/services/svc_wins.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index c9e172da2a..7075944b65 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -8,7 +8,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, diff --git a/source3/services/svc_netlogon.c b/source3/services/svc_netlogon.c index 09e841cf7e..ec379371f0 100644 --- a/source3/services/svc_netlogon.c +++ b/source3/services/svc_netlogon.c @@ -5,7 +5,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, diff --git a/source3/services/svc_rcinit.c b/source3/services/svc_rcinit.c index f60019601f..06ebe3a5fc 100644 --- a/source3/services/svc_rcinit.c +++ b/source3/services/svc_rcinit.c @@ -5,7 +5,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, diff --git a/source3/services/svc_spoolss.c b/source3/services/svc_spoolss.c index 13a1dbb1bd..c7b1ccf1de 100644 --- a/source3/services/svc_spoolss.c +++ b/source3/services/svc_spoolss.c @@ -5,7 +5,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, diff --git a/source3/services/svc_winreg.c b/source3/services/svc_winreg.c index 8fa49d3c3b..f4136c54af 100644 --- a/source3/services/svc_winreg.c +++ b/source3/services/svc_winreg.c @@ -5,7 +5,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, diff --git a/source3/services/svc_wins.c b/source3/services/svc_wins.c index 37cfc99c06..0c2996559d 100644 --- a/source3/services/svc_wins.c +++ b/source3/services/svc_wins.c @@ -5,7 +5,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, -- cgit From 153cfb9c83534b09f15cc16205d7adb19b394928 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/services/services_db.c | 3 +-- source3/services/svc_netlogon.c | 3 +-- source3/services/svc_rcinit.c | 3 +-- source3/services/svc_spoolss.c | 3 +-- source3/services/svc_winreg.c | 3 +-- source3/services/svc_wins.c | 3 +-- 6 files changed, 6 insertions(+), 12 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 7075944b65..075081b202 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -17,8 +17,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" diff --git a/source3/services/svc_netlogon.c b/source3/services/svc_netlogon.c index ec379371f0..11185fd116 100644 --- a/source3/services/svc_netlogon.c +++ b/source3/services/svc_netlogon.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" diff --git a/source3/services/svc_rcinit.c b/source3/services/svc_rcinit.c index 06ebe3a5fc..f65015b059 100644 --- a/source3/services/svc_rcinit.c +++ b/source3/services/svc_rcinit.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" diff --git a/source3/services/svc_spoolss.c b/source3/services/svc_spoolss.c index c7b1ccf1de..9d4113cadf 100644 --- a/source3/services/svc_spoolss.c +++ b/source3/services/svc_spoolss.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" diff --git a/source3/services/svc_winreg.c b/source3/services/svc_winreg.c index f4136c54af..09d25f45e4 100644 --- a/source3/services/svc_winreg.c +++ b/source3/services/svc_winreg.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" diff --git a/source3/services/svc_wins.c b/source3/services/svc_wins.c index 0c2996559d..c9ef5e5b51 100644 --- a/source3/services/svc_wins.c +++ b/source3/services/svc_wins.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" -- cgit From c7b9f06647c1a18bdc42a0815696826304bb2c0a Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 9 Aug 2007 19:03:23 +0000 Subject: r24290: fix debug statments to match function name (This used to be commit 5ee0bfde50645b822cefefe90bc9168faeeb34ff) --- source3/services/services_db.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 075081b202..6811db4b14 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -415,7 +415,7 @@ void svcctl_init_keys( void ) get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { - DEBUG(0,("init_services_keys: key lookup failed! (%s)\n", + DEBUG(0,("svcctl_init_keys: key lookup failed! (%s)\n", dos_errstr(wresult))); return; } @@ -423,7 +423,7 @@ void svcctl_init_keys( void ) /* lookup the available subkeys */ if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) { - DEBUG(0,("init_services_keys: talloc() failed!\n")); + DEBUG(0,("svcctl_init_keys: talloc() failed!\n")); TALLOC_FREE( key ); return; } -- cgit From ff0947fbed841065fce85c64ff4b2a2e8f24f056 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 4 Sep 2007 10:15:04 +0000 Subject: r24949: Remove some static buffers (This used to be commit df648d47ff3c4e24f439fda839653bda98323100) --- source3/services/services_db.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 6811db4b14..f3ec62a01b 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -148,7 +148,7 @@ static char *get_common_service_dispname( const char *servicename ) static char* cleanup_string( const char *string ) { - static pstring clean; + pstring clean; char *begin, *end; pstrcpy( clean, string ); @@ -172,7 +172,7 @@ static char* cleanup_string( const char *string ) end--; } - return begin; + return talloc_strdup(talloc_tos(), begin); } /******************************************************************** -- cgit From f708132de775403f582bd3cf216f7ed76e26932e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 7 Oct 2007 12:56:43 +0000 Subject: r25561: Make use of [un]marshall_sec_desc Minor cleanup only (This used to be commit 4dc4364b68b6b68ae0951a84475e2f9ea8cb1f8c) --- source3/services/services_db.c | 51 ++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 29 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index f3ec62a01b..b2ef6b30f1 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -311,7 +311,8 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, REGVAL_CTR *values; REGSUBKEY_CTR *svc_subkeys; SEC_DESC *sd; - prs_struct ps; + DATA_BLOB sd_blob; + NTSTATUS status; /* add to the list and create the subkey path */ @@ -379,20 +380,20 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, TALLOC_FREE( key_secdesc ); return; } - - /* stream the printer security descriptor */ - - prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key_secdesc, MARSHALL); - - if ( sec_io_desc("sec_desc", &sd, &ps, 0 ) ) { - uint32 offset = prs_offset( &ps ); - regval_ctr_addvalue( values, "Security", REG_BINARY, prs_data_p(&ps), offset ); - store_reg_values( key_secdesc, values ); + + status = marshall_sec_desc(key_secdesc, sd, &sd_blob.data, + &sd_blob.length); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("marshall_sec_desc failed: %s\n", + nt_errstr(status))); + TALLOC_FREE(key_secdesc); + return; } - /* finally cleanup the Security key */ + regval_ctr_addvalue(values, "Security", REG_BINARY, + (const char *)sd_blob.data, sd_blob.length); + store_reg_values( key_secdesc, values ); - prs_mem_free( &ps ); TALLOC_FREE( key_secdesc ); return; @@ -464,13 +465,12 @@ void svcctl_init_keys( void ) SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token ) { REGISTRY_KEY *key; - prs_struct ps; REGVAL_CTR *values; REGISTRY_VALUE *val; - SEC_DESC *sd = NULL; SEC_DESC *ret_sd = NULL; pstring path; WERROR wresult; + NTSTATUS status; /* now add the security descriptor */ @@ -490,31 +490,24 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * } fetch_reg_values( key, values ); + + TALLOC_FREE(key); if ( !(val = regval_ctr_getvalue( values, "Security" )) ) { DEBUG(6,("svcctl_get_secdesc: constructing default secdesc for service [%s]\n", name)); - TALLOC_FREE( key ); return construct_service_sd( ctx ); } - /* stream the printer security descriptor */ - - prs_init( &ps, 0, key, UNMARSHALL); - prs_give_memory( &ps, (char *)regval_data_p(val), regval_size(val), False ); - - if ( !sec_io_desc("sec_desc", &sd, &ps, 0 ) ) { - TALLOC_FREE( key ); + /* stream the service security descriptor */ + + status = unmarshall_sec_desc(ctx, regval_data_p(val), + regval_size(val), &ret_sd); + + if (!NT_STATUS_IS_OK(status)) { return construct_service_sd( ctx ); } - - ret_sd = dup_sec_desc( ctx, sd ); - - /* finally cleanup the Security key */ - - prs_mem_free( &ps ); - TALLOC_FREE( key ); return ret_sd; } -- cgit From e5a951325a6cac8567af3a66de6d2df577508ae4 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" Date: Wed, 10 Oct 2007 15:34:30 -0500 Subject: [GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch. (This used to be commit 5c6c8e1fe93f340005110a7833946191659d88ab) --- source3/services/svc_netlogon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/services') diff --git a/source3/services/svc_netlogon.c b/source3/services/svc_netlogon.c index 11185fd116..c5a5385cdd 100644 --- a/source3/services/svc_netlogon.c +++ b/source3/services/svc_netlogon.c @@ -31,7 +31,7 @@ static WERROR netlogon_status( const char *service, SERVICE_STATUS *service_stat service_status->type = 0x20; service_status->controls_accepted = SVCCTL_ACCEPT_NONE; - if ( share_defined("NETLOGON") ) { + if ( lp_servicenumber("NETLOGON") != -1 ) { service_status->state = SVCCTL_RUNNING; service_status->win32_exit_code = WERR_SERVICE_NEVER_STARTED; } @@ -56,7 +56,7 @@ static WERROR netlogon_stop( const char *service, SERVICE_STATUS *service_status static WERROR netlogon_start( const char *service ) { - if ( !share_defined("NETLOGON") ) + if ( lp_servicenumber("NETLOGON") == -1 ) return WERR_SERVICE_DISABLED; return WERR_ACCESS_DENIED; -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/services/services_db.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index b2ef6b30f1..ccb69d76e4 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -178,7 +178,7 @@ static char* cleanup_string( const char *string ) /******************************************************************** ********************************************************************/ -static BOOL read_init_file( const char *servicename, struct rcinit_file_information **service_info ) +static bool read_init_file( const char *servicename, struct rcinit_file_information **service_info ) { struct rcinit_file_information *info; pstring filepath, str; @@ -516,14 +516,14 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * Wrapper to make storing a Service sd easier ********************************************************************/ -BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, NT_USER_TOKEN *token ) +bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, NT_USER_TOKEN *token ) { REGISTRY_KEY *key; WERROR wresult; pstring path; REGVAL_CTR *values; prs_struct ps; - BOOL ret = False; + bool ret = False; /* now add the security descriptor */ -- cgit From a0f7c3f481e22f77a6f868970f83e27a0d6ba4ad Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 20 Nov 2007 17:57:47 -0800 Subject: Remove pstring from services/*.c Jeremy. (This used to be commit 33aa866195e232f878230bc62e97e1484996afcc) --- source3/services/services_db.c | 302 ++++++++++++++++++++++++----------------- source3/services/svc_rcinit.c | 57 +++++--- 2 files changed, 211 insertions(+), 148 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index ccb69d76e4..07f7aa6002 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -33,7 +33,7 @@ struct service_display_info { const char *description; }; -struct service_display_info builtin_svcs[] = { +struct service_display_info builtin_svcs[] = { { "Spooler", "smbd", "Print Spooler", "Internal service for spooling files to print devices" }, { "NETLOGON", "smbd", "Net Logon", "File service providing access to policy and profile data (not remotely manageable)" }, { "RemoteRegistry", "smbd", "Remote Registry Service", "Internal service providing remote access to " @@ -43,7 +43,7 @@ struct service_display_info builtin_svcs[] = { { NULL, NULL, NULL, NULL } }; -struct service_display_info common_unix_svcs[] = { +struct service_display_info common_unix_svcs[] = { { "cups", NULL, "Common Unix Printing System","Provides unified printing support for all operating systems" }, { "postfix", NULL, "Internet Mail Service", "Provides support for sending and receiving electonic mail" }, { "sendmail", NULL, "Internet Mail Service", "Provides support for sending and receiving electonic mail" }, @@ -88,27 +88,27 @@ struct service_display_info common_unix_svcs[] = { static SEC_DESC* construct_service_sd( TALLOC_CTX *ctx ) { - SEC_ACE ace[4]; + SEC_ACE ace[4]; SEC_ACCESS mask; size_t i = 0; SEC_DESC *sd; SEC_ACL *acl; size_t sd_size; - + /* basic access for Everyone */ - + init_sec_access(&mask, SERVICE_READ_ACCESS ); init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0); - + init_sec_access(&mask,SERVICE_EXECUTE_ACCESS ); init_sec_ace(&ace[i++], &global_sid_Builtin_Power_Users, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0); - + init_sec_access(&mask,SERVICE_ALL_ACCESS ); init_sec_ace(&ace[i++], &global_sid_Builtin_Server_Operators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0); init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0); - + /* create the security descriptor */ - + if ( !(acl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) ) return NULL; @@ -127,52 +127,58 @@ static char *get_common_service_dispname( const char *servicename ) { static fstring dispname; int i; - + for ( i=0; common_unix_svcs[i].servicename; i++ ) { - if ( strequal( servicename, common_unix_svcs[i].servicename ) ) { - fstr_sprintf( dispname, "%s (%s)", + if (strequal(servicename, common_unix_svcs[i].servicename)) { + fstr_sprintf( dispname, "%s (%s)", common_unix_svcs[i].dispname, common_unix_svcs[i].servicename ); - + return dispname; } - } - + } + fstrcpy( dispname, servicename ); - + return dispname; } /******************************************************************** ********************************************************************/ -static char* cleanup_string( const char *string ) +static char *cleanup_string( const char *string ) { - pstring clean; + char *clean = NULL; char *begin, *end; + TALLOC_CTX *ctx = talloc_tos(); - pstrcpy( clean, string ); + clean = talloc_strdup(ctx, string); + if (!clean) { + return NULL; + } begin = clean; - + /* trim any beginning whilespace */ - - while ( isspace(*begin) ) + + while (isspace(*begin)) { begin++; + } - if ( *begin == '\0' ) + if (*begin == '\0') { return NULL; - + } + /* trim any trailing whitespace or carriage returns. Start at the end and move backwards */ - + end = begin + strlen(begin) - 1; - + while ( isspace(*end) || *end=='\n' || *end=='\r' ) { *end = '\0'; end--; } - return talloc_strdup(talloc_tos(), begin); + return begin; } /******************************************************************** @@ -181,50 +187,57 @@ static char* cleanup_string( const char *string ) static bool read_init_file( const char *servicename, struct rcinit_file_information **service_info ) { struct rcinit_file_information *info; - pstring filepath, str; + char *filepath = NULL; + char str[1024]; XFILE *f; char *p; - + if ( !(info = TALLOC_ZERO_P( NULL, struct rcinit_file_information ) ) ) return False; - + /* attempt the file open */ - - pstr_sprintf( filepath, "%s/%s/%s", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, servicename ); - if ( !(f = x_fopen( filepath, O_RDONLY, 0 )) ) { + + filepath = talloc_asprintf(info, "%s/%s/%s", dyn_LIBDIR, + SVCCTL_SCRIPT_DIR, servicename); + if (!filepath) { + TALLOC_FREE(info); + return false; + } + if (!(f = x_fopen( filepath, O_RDONLY, 0 ))) { DEBUG(0,("read_init_file: failed to open [%s]\n", filepath)); TALLOC_FREE(info); - return False; + return false; } - + while ( (x_fgets( str, sizeof(str)-1, f )) != NULL ) { - /* ignore everything that is not a full line + /* ignore everything that is not a full line comment starting with a '#' */ - + if ( str[0] != '#' ) continue; - + /* Look for a line like '^#.*Description:' */ - + if ( (p = strstr( str, "Description:" )) != NULL ) { char *desc; p += strlen( "Description:" ) + 1; - if ( !p ) + if ( !p ) break; - + if ( (desc = cleanup_string(p)) != NULL ) info->description = talloc_strdup( info, desc ); } } - + x_fclose( f ); - + if ( !info->description ) info->description = talloc_strdup( info, "External Unix Service" ); - + *service_info = info; - + TALLOC_FREE(filepath); + return True; } @@ -237,50 +250,62 @@ static void fill_service_values( const char *name, REGVAL_CTR *values ) { UNISTR2 data, dname, ipath, description; uint32 dword; - pstring pstr; int i; - + /* These values are hardcoded in all QueryServiceConfig() replies. I'm just storing them here for cosmetic purposes */ - + dword = SVCCTL_AUTO_START; regval_ctr_addvalue( values, "Start", REG_DWORD, (char*)&dword, sizeof(uint32)); - + dword = SVCCTL_WIN32_OWN_PROC; regval_ctr_addvalue( values, "Type", REG_DWORD, (char*)&dword, sizeof(uint32)); dword = SVCCTL_SVC_ERROR_NORMAL; regval_ctr_addvalue( values, "ErrorControl", REG_DWORD, (char*)&dword, sizeof(uint32)); - + /* everything runs as LocalSystem */ - + init_unistr2( &data, "LocalSystem", UNI_STR_TERMINATE ); regval_ctr_addvalue( values, "ObjectName", REG_SZ, (char*)data.buffer, data.uni_str_len*2); - + /* special considerations for internal services and the DisplayName value */ - + for ( i=0; builtin_svcs[i].servicename; i++ ) { if ( strequal( name, builtin_svcs[i].servicename ) ) { - pstr_sprintf( pstr, "%s/%s/%s",dyn_LIBDIR, SVCCTL_SCRIPT_DIR, builtin_svcs[i].daemon ); - init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); + char *pstr = NULL; + if (asprintf(&pstr, "%s/%s/%s", + dyn_LIBDIR, SVCCTL_SCRIPT_DIR, + builtin_svcs[i].daemon) > 0) { + init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); + SAFE_FREE(pstr); + } else { + init_unistr2( &ipath, "", UNI_STR_TERMINATE ); + } init_unistr2( &description, builtin_svcs[i].description, UNI_STR_TERMINATE ); init_unistr2( &dname, builtin_svcs[i].dispname, UNI_STR_TERMINATE ); break; } - } - + } + /* default to an external service if we haven't found a match */ - + if ( builtin_svcs[i].servicename == NULL ) { + char *pstr = NULL; struct rcinit_file_information *init_info = NULL; - pstr_sprintf( pstr, "%s/%s/%s",dyn_LIBDIR, SVCCTL_SCRIPT_DIR, name ); - init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); - + if (asprintf(&pstr, "%s/%s/%s",dyn_LIBDIR, + SVCCTL_SCRIPT_DIR, name) > 0) { + init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); + SAFE_FREE(pstr); + } else { + init_unistr2( &ipath, "", UNI_STR_TERMINATE ); + } + /* lookup common unix display names */ init_unistr2( &dname, get_common_service_dispname( name ), UNI_STR_TERMINATE ); - /* get info from init file itself */ + /* get info from init file itself */ if ( read_init_file( name, &init_info ) ) { init_unistr2( &description, init_info->description, UNI_STR_TERMINATE ); TALLOC_FREE( init_info ); @@ -289,25 +314,25 @@ static void fill_service_values( const char *name, REGVAL_CTR *values ) init_unistr2( &description, "External Unix Service", UNI_STR_TERMINATE ); } } - + /* add the new values */ - + regval_ctr_addvalue( values, "DisplayName", REG_SZ, (char*)dname.buffer, dname.uni_str_len*2); regval_ctr_addvalue( values, "ImagePath", REG_SZ, (char*)ipath.buffer, ipath.uni_str_len*2); regval_ctr_addvalue( values, "Description", REG_SZ, (char*)description.buffer, description.uni_str_len*2); - + return; } /******************************************************************** ********************************************************************/ -static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, +static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, const char *name ) { REGISTRY_KEY *key_service, *key_secdesc; WERROR wresult; - pstring path; + char *path = NULL; REGVAL_CTR *values; REGSUBKEY_CTR *svc_subkeys; SEC_DESC *sd; @@ -321,15 +346,19 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* open the new service key */ - pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); + if (asprintf(&path, "%s\\%s", KEY_SERVICES, name) < 0) { + return; + } wresult = regkey_open_internal( NULL, &key_service, path, get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { - DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", + DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); + SAFE_FREE(path); return; } - + SAFE_FREE(path); + /* add the 'Security' key */ if ( !(svc_subkeys = TALLOC_ZERO_P( key_service, REGSUBKEY_CTR )) ) { @@ -337,13 +366,13 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, TALLOC_FREE( key_service ); return; } - + fetch_reg_keys( key_service, svc_subkeys ); regsubkey_ctr_addkey( svc_subkeys, "Security" ); store_reg_keys( key_service, svc_subkeys ); /* now for the service values */ - + if ( !(values = TALLOC_ZERO_P( key_service, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); TALLOC_FREE( key_service ); @@ -359,15 +388,19 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, /* now add the security descriptor */ - pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); + if (asprintf(&path, "%s\\%s\\%s", KEY_SERVICES, name, "Security") < 0) { + return; + } wresult = regkey_open_internal( NULL, &key_secdesc, path, get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { - DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", + DEBUG(0,("add_new_svc_name: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); TALLOC_FREE( key_secdesc ); + SAFE_FREE(path); return; } + SAFE_FREE(path); if ( !(values = TALLOC_ZERO_P( key_secdesc, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); @@ -389,11 +422,11 @@ static void add_new_svc_name( REGISTRY_KEY *key_parent, REGSUBKEY_CTR *subkeys, TALLOC_FREE(key_secdesc); return; } - + regval_ctr_addvalue(values, "Security", REG_BINARY, (const char *)sd_blob.data, sd_blob.length); store_reg_values( key_secdesc, values ); - + TALLOC_FREE( key_secdesc ); return; @@ -409,35 +442,35 @@ void svcctl_init_keys( void ) REGSUBKEY_CTR *subkeys; REGISTRY_KEY *key = NULL; WERROR wresult; - + /* bad mojo here if the lookup failed. Should not happen */ - + wresult = regkey_open_internal( NULL, &key, KEY_SERVICES, get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { - DEBUG(0,("svcctl_init_keys: key lookup failed! (%s)\n", + DEBUG(0,("svcctl_init_keys: key lookup failed! (%s)\n", dos_errstr(wresult))); return; } - - /* lookup the available subkeys */ - + + /* lookup the available subkeys */ + if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) { DEBUG(0,("svcctl_init_keys: talloc() failed!\n")); TALLOC_FREE( key ); return; } - + fetch_reg_keys( key, subkeys ); - + /* the builting services exist */ - + for ( i=0; builtin_svcs[i].servicename; i++ ) add_new_svc_name( key, subkeys, builtin_svcs[i].servicename ); - + for ( i=0; service_list && service_list[i]; i++ ) { - + /* only add new services */ if ( regsubkey_ctr_key_exists( subkeys, service_list[i] ) ) continue; @@ -458,30 +491,34 @@ void svcctl_init_keys( void ) /******************************************************************** This is where we do the dirty work of filling in things like the - Display name, Description, etc...Always return a default secdesc + Display name, Description, etc...Always return a default secdesc in case of any failure. ********************************************************************/ -SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token ) +SEC_DESC *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token ) { REGISTRY_KEY *key; REGVAL_CTR *values; REGISTRY_VALUE *val; SEC_DESC *ret_sd = NULL; - pstring path; + char *path= NULL; WERROR wresult; NTSTATUS status; - + /* now add the security descriptor */ - pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); + if (asprintf(&path, "%s\\%s\\%s", KEY_SERVICES, name, "Security") < 0) { + return NULL; + } wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { - DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", + DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); + SAFE_FREE(path); return NULL; } + SAFE_FREE(path); if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); @@ -492,13 +529,12 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * fetch_reg_values( key, values ); TALLOC_FREE(key); - + if ( !(val = regval_ctr_getvalue( values, "Security" )) ) { DEBUG(6,("svcctl_get_secdesc: constructing default secdesc for service [%s]\n", name)); return construct_service_sd( ctx ); } - /* stream the service security descriptor */ @@ -520,40 +556,43 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, { REGISTRY_KEY *key; WERROR wresult; - pstring path; + char *path = NULL; REGVAL_CTR *values; prs_struct ps; bool ret = False; - + /* now add the security descriptor */ - pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); + if (asprintf(&path, "%s\\%s\\%s", KEY_SERVICES, name, "Security") < 0) { + return false; + } wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { - DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", + DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); + SAFE_FREE(path); return False; } + SAFE_FREE(path); if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("add_new_svc_name: talloc() failed!\n")); TALLOC_FREE( key ); return False; } - + /* stream the printer security descriptor */ - prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key, MARSHALL); - + if ( sec_io_desc("sec_desc", &sec_desc, &ps, 0 ) ) { uint32 offset = prs_offset( &ps ); regval_ctr_addvalue( values, "Security", REG_BINARY, prs_data_p(&ps), offset ); ret = store_reg_values( key, values ); } - + /* cleanup */ - + prs_mem_free( &ps ); TALLOC_FREE( key); @@ -563,25 +602,29 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, /******************************************************************** ********************************************************************/ -char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) +char *svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) { static fstring display_name; - REGISTRY_KEY *key; + REGISTRY_KEY *key = NULL; REGVAL_CTR *values; REGISTRY_VALUE *val; - pstring path; + char *path = NULL; WERROR wresult; - + /* now add the security descriptor */ - pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); + if (asprintf(&path, "%s\\%s", KEY_SERVICES, name) < 0) { + return NULL; + } wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); + SAFE_FREE(path); goto fail; } + SAFE_FREE(path); if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n")); @@ -590,14 +633,14 @@ char* svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) } fetch_reg_values( key, values ); - + if ( !(val = regval_ctr_getvalue( values, "DisplayName" )) ) goto fail; rpcstr_pull( display_name, regval_data_p(val), sizeof(display_name), regval_size(val), 0 ); TALLOC_FREE( key ); - + return display_name; fail: @@ -610,25 +653,29 @@ fail: /******************************************************************** ********************************************************************/ -char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) +char *svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) { static fstring description; - REGISTRY_KEY *key; + REGISTRY_KEY *key = NULL; REGVAL_CTR *values; REGISTRY_VALUE *val; - pstring path; + char *path = NULL; WERROR wresult; - + /* now add the security descriptor */ - pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); + if (asprintf(&path, "%s\\%s", KEY_SERVICES, name) < 0) { + return NULL; + } wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); + SAFE_FREE(path); return NULL; } + SAFE_FREE(path); if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n")); @@ -637,14 +684,14 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) } fetch_reg_values( key, values ); - + if ( !(val = regval_ctr_getvalue( values, "Description" )) ) fstrcpy( description, "Unix Service"); else rpcstr_pull( description, regval_data_p(val), sizeof(description), regval_size(val), 0 ); TALLOC_FREE( key ); - + return description; } @@ -652,34 +699,35 @@ char* svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) /******************************************************************** ********************************************************************/ -REGVAL_CTR* svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token ) +REGVAL_CTR *svcctl_fetch_regvalues( const char *name, NT_USER_TOKEN *token ) { - REGISTRY_KEY *key; + REGISTRY_KEY *key = NULL; REGVAL_CTR *values; - pstring path; + char *path = NULL; WERROR wresult; - + /* now add the security descriptor */ - pstr_sprintf( path, "%s\\%s", KEY_SERVICES, name ); + if (asprintf(&path, "%s\\%s", KEY_SERVICES, name) < 0) { + return NULL; + } wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { - DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n", + DEBUG(0,("svcctl_fetch_regvalues: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); + SAFE_FREE(path); return NULL; } + SAFE_FREE(path); if ( !(values = TALLOC_ZERO_P( NULL, REGVAL_CTR )) ) { DEBUG(0,("svcctl_fetch_regvalues: talloc() failed!\n")); TALLOC_FREE( key ); return NULL; } - fetch_reg_values( key, values ); TALLOC_FREE( key ); - return values; } - diff --git a/source3/services/svc_rcinit.c b/source3/services/svc_rcinit.c index f65015b059..66f89f2248 100644 --- a/source3/services/svc_rcinit.c +++ b/source3/services/svc_rcinit.c @@ -24,20 +24,25 @@ static WERROR rcinit_stop( const char *service, SERVICE_STATUS *status ) { - pstring command; + char *command = NULL; int ret, fd; - - pstr_sprintf( command, "%s/%s/%s stop", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service ); - + + if (asprintf(&command, "%s/%s/%s stop", + dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service) < 0) { + return WERR_NOMEM; + } + /* we've already performed the access check when the service was opened */ - + become_root(); ret = smbrun( command , &fd ); unbecome_root(); - + DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret)); close(fd); - + + SAFE_FREE(command); + ZERO_STRUCTP( status ); status->type = 0x0020; status->state = (ret == 0 ) ? 0x0001 : 0x0004; @@ -51,19 +56,24 @@ static WERROR rcinit_stop( const char *service, SERVICE_STATUS *status ) static WERROR rcinit_start( const char *service ) { - pstring command; + char *command = NULL; int ret, fd; - - pstr_sprintf( command, "%s/%s/%s start", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service ); - + + if (asprintf(&command, "%s/%s/%s start", + dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service) < 0) { + return WERR_NOMEM; + } + /* we've already performed the access check when the service was opened */ - + become_root(); ret = smbrun( command , &fd ); unbecome_root(); - + DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret)); - close(fd); + close(fd); + + SAFE_FREE(command); return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED; } @@ -73,22 +83,27 @@ static WERROR rcinit_start( const char *service ) static WERROR rcinit_status( const char *service, SERVICE_STATUS *status ) { - pstring command; + char *command = NULL; int ret, fd; - - pstr_sprintf( command, "%s/%s/%s status", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service ); - + + if (asprintf(&command, "%s/%s/%s status", + dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service) < 0) { + return WERR_NOMEM; + } + /* we've already performed the access check when the service was opened */ /* assume as return code of 0 means that the service is ok. Anything else is STOPPED */ - + become_root(); ret = smbrun( command , &fd ); unbecome_root(); - + DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret)); close(fd); - + + SAFE_FREE(command); + ZERO_STRUCTP( status ); status->type = 0x0020; status->state = (ret == 0 ) ? 0x0004 : 0x0001; -- cgit From 7faee02d0d351c5c039e8f1be7e82ce3a93cbe96 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Dec 2007 11:30:37 -0800 Subject: Remove the char[1024] strings from dynconfig. Replace them with malloc'ing accessor functions. Should save a lot of static space :-). Jeremy. (This used to be commit 52dc5eaef2106015b3a8b659e818bdb15ad94b05) --- source3/services/services_db.c | 6 +++--- source3/services/svc_rcinit.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 07f7aa6002..430c58f50d 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -197,7 +197,7 @@ static bool read_init_file( const char *servicename, struct rcinit_file_informat /* attempt the file open */ - filepath = talloc_asprintf(info, "%s/%s/%s", dyn_LIBDIR, + filepath = talloc_asprintf(info, "%s/%s/%s", get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR, servicename); if (!filepath) { TALLOC_FREE(info); @@ -275,7 +275,7 @@ static void fill_service_values( const char *name, REGVAL_CTR *values ) if ( strequal( name, builtin_svcs[i].servicename ) ) { char *pstr = NULL; if (asprintf(&pstr, "%s/%s/%s", - dyn_LIBDIR, SVCCTL_SCRIPT_DIR, + get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR, builtin_svcs[i].daemon) > 0) { init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); SAFE_FREE(pstr); @@ -294,7 +294,7 @@ static void fill_service_values( const char *name, REGVAL_CTR *values ) char *pstr = NULL; struct rcinit_file_information *init_info = NULL; - if (asprintf(&pstr, "%s/%s/%s",dyn_LIBDIR, + if (asprintf(&pstr, "%s/%s/%s",get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR, name) > 0) { init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); SAFE_FREE(pstr); diff --git a/source3/services/svc_rcinit.c b/source3/services/svc_rcinit.c index 66f89f2248..b7684b951c 100644 --- a/source3/services/svc_rcinit.c +++ b/source3/services/svc_rcinit.c @@ -28,7 +28,7 @@ static WERROR rcinit_stop( const char *service, SERVICE_STATUS *status ) int ret, fd; if (asprintf(&command, "%s/%s/%s stop", - dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service) < 0) { + get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR, service) < 0) { return WERR_NOMEM; } @@ -60,7 +60,7 @@ static WERROR rcinit_start( const char *service ) int ret, fd; if (asprintf(&command, "%s/%s/%s start", - dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service) < 0) { + get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR, service) < 0) { return WERR_NOMEM; } @@ -87,7 +87,7 @@ static WERROR rcinit_status( const char *service, SERVICE_STATUS *status ) int ret, fd; if (asprintf(&command, "%s/%s/%s status", - dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service) < 0) { + get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR, service) < 0) { return WERR_NOMEM; } -- cgit From e3efe7cd7e11be5a78ddce9a49316b516ab81ba3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 17 Dec 2007 18:00:43 -0800 Subject: More static fstring elimination. Jeremy. (This used to be commit b4dfec09e89428cac9b21a94ce4d24e60d4a54f4) --- source3/services/services_db.c | 48 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 430c58f50d..c57b29cc80 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -125,22 +125,22 @@ static SEC_DESC* construct_service_sd( TALLOC_CTX *ctx ) static char *get_common_service_dispname( const char *servicename ) { - static fstring dispname; int i; for ( i=0; common_unix_svcs[i].servicename; i++ ) { if (strequal(servicename, common_unix_svcs[i].servicename)) { - fstr_sprintf( dispname, "%s (%s)", + char *dispname; + if (asprintf(&dispname, + "%s (%s)", common_unix_svcs[i].dispname, - common_unix_svcs[i].servicename ); - + common_unix_svcs[i].servicename) < 0) { + return NULL; + } return dispname; } } - fstrcpy( dispname, servicename ); - - return dispname; + return SMB_STRDUP(servicename ); } /******************************************************************** @@ -292,6 +292,7 @@ static void fill_service_values( const char *name, REGVAL_CTR *values ) if ( builtin_svcs[i].servicename == NULL ) { char *pstr = NULL; + char *dispname = NULL; struct rcinit_file_information *init_info = NULL; if (asprintf(&pstr, "%s/%s/%s",get_dyn_LIBDIR(), @@ -303,7 +304,9 @@ static void fill_service_values( const char *name, REGVAL_CTR *values ) } /* lookup common unix display names */ - init_unistr2( &dname, get_common_service_dispname( name ), UNI_STR_TERMINATE ); + dispname = get_common_service_dispname(name); + init_unistr2( &dname, dispname ? dispname : "", UNI_STR_TERMINATE ); + SAFE_FREE(dispname); /* get info from init file itself */ if ( read_init_file( name, &init_info ) ) { @@ -602,9 +605,9 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, /******************************************************************** ********************************************************************/ -char *svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) +const char *svcctl_lookup_dispname(TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token ) { - static fstring display_name; + char *display_name = NULL; REGISTRY_KEY *key = NULL; REGVAL_CTR *values; REGISTRY_VALUE *val; @@ -637,7 +640,7 @@ char *svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) if ( !(val = regval_ctr_getvalue( values, "DisplayName" )) ) goto fail; - rpcstr_pull( display_name, regval_data_p(val), sizeof(display_name), regval_size(val), 0 ); + rpcstr_pull_talloc(ctx, &display_name, regval_data_p(val), regval_size(val), 0 ); TALLOC_FREE( key ); @@ -646,16 +649,15 @@ char *svcctl_lookup_dispname( const char *name, NT_USER_TOKEN *token ) fail: /* default to returning the service name */ TALLOC_FREE( key ); - fstrcpy( display_name, name ); - return display_name; + return talloc_strdup(ctx, name); } /******************************************************************** ********************************************************************/ -char *svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) +const char *svcctl_lookup_description(TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN *token ) { - static fstring description; + char *description = NULL; REGISTRY_KEY *key = NULL; REGVAL_CTR *values; REGISTRY_VALUE *val; @@ -670,7 +672,7 @@ char *svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) wresult = regkey_open_internal( NULL, &key, path, token, REG_KEY_READ ); if ( !W_ERROR_IS_OK(wresult) ) { - DEBUG(0,("svcctl_lookup_dispname: key lookup failed! [%s] (%s)\n", + DEBUG(0,("svcctl_lookup_description: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); SAFE_FREE(path); return NULL; @@ -678,19 +680,19 @@ char *svcctl_lookup_description( const char *name, NT_USER_TOKEN *token ) SAFE_FREE(path); if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { - DEBUG(0,("svcctl_lookup_dispname: talloc() failed!\n")); + DEBUG(0,("svcctl_lookup_description: talloc() failed!\n")); TALLOC_FREE( key ); return NULL; } fetch_reg_values( key, values ); - if ( !(val = regval_ctr_getvalue( values, "Description" )) ) - fstrcpy( description, "Unix Service"); - else - rpcstr_pull( description, regval_data_p(val), sizeof(description), regval_size(val), 0 ); - - TALLOC_FREE( key ); + if ( !(val = regval_ctr_getvalue( values, "Description" )) ) { + TALLOC_FREE( key ); + return "Unix Service"; + } + rpcstr_pull_talloc(ctx, &description, regval_data_p(val), regval_size(val), 0 ); + TALLOC_FREE(key); return description; } -- cgit From 99b86e4a266b99634f6a65015f6df115c421d3e5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 20 Dec 2007 22:27:01 +0100 Subject: Some C++ fixes (This used to be commit 5c392c4c6e277a24d0d477902dc7856b2b46ee53) --- source3/services/services_db.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index c57b29cc80..b1daae4df8 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -112,7 +112,9 @@ static SEC_DESC* construct_service_sd( TALLOC_CTX *ctx ) if ( !(acl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) ) return NULL; - if ( !(sd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, acl, &sd_size)) ) + if ( !(sd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1, + SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, + acl, &sd_size)) ) return NULL; return sd; -- cgit From 59c0aa3afd3d4d9ec4b248ef89d32fdcdbd7eca2 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 21 Jan 2008 15:14:16 +0100 Subject: Fix two debug messages. Michael (This used to be commit 35e23368dd4240a3c907b4cee882f51119032527) --- source3/services/services_db.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index b1daae4df8..d4e144d5ff 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -526,7 +526,7 @@ SEC_DESC *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * SAFE_FREE(path); if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { - DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + DEBUG(0,("svcctl_get_secdesc: talloc() failed!\n")); TALLOC_FREE( key ); return NULL; } @@ -582,7 +582,7 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, SAFE_FREE(path); if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { - DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + DEBUG(0,("svcctl_set_secdesc: talloc() failed!\n")); TALLOC_FREE( key ); return False; } -- cgit From 1638941ba296fff1a5b22ed34dbe6eb7e0dbb4b2 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 18 Feb 2008 16:58:24 +0100 Subject: Fix a comment typo. Michael (This used to be commit 00e2dd36b38fcf92d76a0e79860cf9ca6a3d027e) --- source3/services/services_db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index d4e144d5ff..37440a299f 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -469,7 +469,7 @@ void svcctl_init_keys( void ) fetch_reg_keys( key, subkeys ); - /* the builting services exist */ + /* the builtin services exist */ for ( i=0; builtin_svcs[i].servicename; i++ ) add_new_svc_name( key, subkeys, builtin_svcs[i].servicename ); -- cgit From 5cd707f82c238633df9f89ea45d71e2a92b48161 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 18 Feb 2008 17:23:41 +0100 Subject: Add a check for success of fetch_reg_values(). Michael (This used to be commit ba69097f37086537e6b2606fceeb874f6d3e4e1c) --- source3/services/services_db.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 37440a299f..89095c628d 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -531,7 +531,11 @@ SEC_DESC *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * return NULL; } - fetch_reg_values( key, values ); + if (fetch_reg_values( key, values ) == -1) { + DEBUG(0, ("Error getting registry values\n")); + TALLOC_FREE(key); + return NULL; + } TALLOC_FREE(key); -- cgit From 8ba088516aa34505849ef0a8639687bec22c5750 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 18 Feb 2008 17:38:19 +0100 Subject: Fix segfault in svcctl_get_secdesc(): prevent premature TALLOC_FREE. This crash was triggered by (e.g.) net rpc service status. This patch prevents premature freeing of memory and creates a common exit point to the function. Michael (This used to be commit f1fb9fd6f14fc53629871cbe4b8558ad5acc14f0) --- source3/services/services_db.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 89095c628d..ae83e72697 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -520,29 +520,21 @@ SEC_DESC *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", path, dos_errstr(wresult))); - SAFE_FREE(path); - return NULL; + goto done; } - SAFE_FREE(path); if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { DEBUG(0,("svcctl_get_secdesc: talloc() failed!\n")); - TALLOC_FREE( key ); - return NULL; + goto done; } if (fetch_reg_values( key, values ) == -1) { DEBUG(0, ("Error getting registry values\n")); - TALLOC_FREE(key); - return NULL; + goto done; } - TALLOC_FREE(key); - if ( !(val = regval_ctr_getvalue( values, "Security" )) ) { - DEBUG(6,("svcctl_get_secdesc: constructing default secdesc for service [%s]\n", - name)); - return construct_service_sd( ctx ); + goto fallback_to_default_sd; } /* stream the service security descriptor */ @@ -550,10 +542,18 @@ SEC_DESC *svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * status = unmarshall_sec_desc(ctx, regval_data_p(val), regval_size(val), &ret_sd); - if (!NT_STATUS_IS_OK(status)) { - return construct_service_sd( ctx ); + if (NT_STATUS_IS_OK(status)) { + goto done; } +fallback_to_default_sd: + DEBUG(6, ("svcctl_get_secdesc: constructing default secdesc for " + "service [%s]\n", name)); + ret_sd = construct_service_sd(ctx); + +done: + SAFE_FREE(path); + TALLOC_FREE(key); return ret_sd; } -- cgit From e06aa46b9fab1e107fea8f6453fb13deffa91e96 Mon Sep 17 00:00:00 2001 From: Marc VanHeyningen Date: Fri, 14 Mar 2008 14:26:28 -0800 Subject: Coverity fixes (This used to be commit 3fc85d22590550f0539215d020e4411bf5b14363) --- source3/services/services_db.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index ae83e72697..620b036932 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -592,7 +592,12 @@ bool svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, } /* stream the printer security descriptor */ - prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key, MARSHALL); + + if (!prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key, MARSHALL)) { + DEBUG(0,("svcctl_set_secdesc: prs_init() failed!\n")); + TALLOC_FREE( key ); + return False; + } if ( sec_io_desc("sec_desc", &sec_desc, &ps, 0 ) ) { uint32 offset = prs_offset( &ps ); -- cgit From 04e697891bc5857acd4f28c10678204febae710e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 17 Jun 2008 16:06:42 +0200 Subject: Fix a memleak in svcctl_init_keys() (This used to be commit 675bb53398ba29c53d2dcf3c7122cf4770c2f938) --- source3/services/services_db.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 620b036932..ae9fe1aeb7 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -447,15 +447,22 @@ void svcctl_init_keys( void ) REGSUBKEY_CTR *subkeys; REGISTRY_KEY *key = NULL; WERROR wresult; + struct nt_user_token *token = get_root_nt_token(); + + if (token == NULL) { + DEBUG(0, ("svcctl_init_keys: get_root_nt_token failed\n")); + return; + } /* bad mojo here if the lookup failed. Should not happen */ wresult = regkey_open_internal( NULL, &key, KEY_SERVICES, - get_root_nt_token(), REG_KEY_ALL ); + token, REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_init_keys: key lookup failed! (%s)\n", dos_errstr(wresult))); + TALLOC_FREE(token); return; } @@ -464,6 +471,7 @@ void svcctl_init_keys( void ) if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) { DEBUG(0,("svcctl_init_keys: talloc() failed!\n")); TALLOC_FREE( key ); + TALLOC_FREE(token); return; } @@ -486,6 +494,7 @@ void svcctl_init_keys( void ) } TALLOC_FREE( key ); + TALLOC_FREE(token); /* initialize the control hooks */ -- cgit From 2b7fca9e79fa62011aed64f92e5bbabde7444caa Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 18 Jun 2008 16:30:37 +0200 Subject: Revert "Fix a memleak in svcctl_init_keys()" This reverts commit b1afb31f3cadd4749bf6e3eb5d8935588bf8ebfc. This one is very strange: I need to investigate why valgrind showed it as leaking, and why in my initial tests this did not fail. (cherry picked from commit 24730f5981efb920811e7929a9483bd72bb0984c) (This used to be commit b1e8e5d173cdaa3fb9c1fb1d9aacf8e665bc5d61) --- source3/services/services_db.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index ae9fe1aeb7..620b036932 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -447,22 +447,15 @@ void svcctl_init_keys( void ) REGSUBKEY_CTR *subkeys; REGISTRY_KEY *key = NULL; WERROR wresult; - struct nt_user_token *token = get_root_nt_token(); - - if (token == NULL) { - DEBUG(0, ("svcctl_init_keys: get_root_nt_token failed\n")); - return; - } /* bad mojo here if the lookup failed. Should not happen */ wresult = regkey_open_internal( NULL, &key, KEY_SERVICES, - token, REG_KEY_ALL ); + get_root_nt_token(), REG_KEY_ALL ); if ( !W_ERROR_IS_OK(wresult) ) { DEBUG(0,("svcctl_init_keys: key lookup failed! (%s)\n", dos_errstr(wresult))); - TALLOC_FREE(token); return; } @@ -471,7 +464,6 @@ void svcctl_init_keys( void ) if ( !(subkeys = TALLOC_ZERO_P( key, REGSUBKEY_CTR )) ) { DEBUG(0,("svcctl_init_keys: talloc() failed!\n")); TALLOC_FREE( key ); - TALLOC_FREE(token); return; } @@ -494,7 +486,6 @@ void svcctl_init_keys( void ) } TALLOC_FREE( key ); - TALLOC_FREE(token); /* initialize the control hooks */ -- cgit From 8829b424fe10817fdc65138c94cd435a265ee05b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 15 Aug 2008 00:50:56 +0200 Subject: svcctl: use MODULESDIR instead of LIBDIR for the svcctl script directory. Michael (This used to be commit bb19634138cfd1f527c44e16a44aa21ebee50c1c) --- source3/services/services_db.c | 6 +++--- source3/services/svc_rcinit.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/services') diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 620b036932..49761c3233 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -199,7 +199,7 @@ static bool read_init_file( const char *servicename, struct rcinit_file_informat /* attempt the file open */ - filepath = talloc_asprintf(info, "%s/%s/%s", get_dyn_LIBDIR(), + filepath = talloc_asprintf(info, "%s/%s/%s", get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, servicename); if (!filepath) { TALLOC_FREE(info); @@ -277,7 +277,7 @@ static void fill_service_values( const char *name, REGVAL_CTR *values ) if ( strequal( name, builtin_svcs[i].servicename ) ) { char *pstr = NULL; if (asprintf(&pstr, "%s/%s/%s", - get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR, + get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, builtin_svcs[i].daemon) > 0) { init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); SAFE_FREE(pstr); @@ -297,7 +297,7 @@ static void fill_service_values( const char *name, REGVAL_CTR *values ) char *dispname = NULL; struct rcinit_file_information *init_info = NULL; - if (asprintf(&pstr, "%s/%s/%s",get_dyn_LIBDIR(), + if (asprintf(&pstr, "%s/%s/%s",get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, name) > 0) { init_unistr2( &ipath, pstr, UNI_STR_TERMINATE ); SAFE_FREE(pstr); diff --git a/source3/services/svc_rcinit.c b/source3/services/svc_rcinit.c index b7684b951c..3d9e6673a0 100644 --- a/source3/services/svc_rcinit.c +++ b/source3/services/svc_rcinit.c @@ -28,7 +28,7 @@ static WERROR rcinit_stop( const char *service, SERVICE_STATUS *status ) int ret, fd; if (asprintf(&command, "%s/%s/%s stop", - get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR, service) < 0) { + get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, service) < 0) { return WERR_NOMEM; } @@ -60,7 +60,7 @@ static WERROR rcinit_start( const char *service ) int ret, fd; if (asprintf(&command, "%s/%s/%s start", - get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR, service) < 0) { + get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, service) < 0) { return WERR_NOMEM; } @@ -87,7 +87,7 @@ static WERROR rcinit_status( const char *service, SERVICE_STATUS *status ) int ret, fd; if (asprintf(&command, "%s/%s/%s status", - get_dyn_LIBDIR(), SVCCTL_SCRIPT_DIR, service) < 0) { + get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, service) < 0) { return WERR_NOMEM; } -- cgit