return 1;
/* Register the service Handler function */
- svcHandle = RegisterServiceCtrlHandler(service_name, WIN32_svcHandler);
+ svcHandle = RegisterServiceCtrlHandler(service_name.c_str(), WIN32_svcHandler);
if (svcHandle == 0)
return 1;
SC_HANDLE schService;
SC_HANDLE schSCManager;
- if (!service_name)
- service_name = xstrdup(APP_SHORTNAME);
+ if (service_name.isEmpty())
+ service_name = SBuf(APP_SHORTNAME);
- strcat(REGKEY, service_name);
+ const char *service = service_name.c_str();
+ strcat(REGKEY, service);
- keys[4] = service_name;
+ keys[4] = service;
schSCManager = OpenSCManager(NULL, /* machine (NULL == local) */
NULL, /* database (NULL == default) */
if (!schSCManager)
fprintf(stderr, "OpenSCManager failed\n");
else {
- schService = OpenService(schSCManager, service_name, SERVICE_ALL_ACCESS);
+ schService = OpenService(schSCManager, service, SERVICE_ALL_ACCESS);
if (schService == NULL)
fprintf(stderr, "OpenService failed\n");
if (DeleteService(schService) == 0)
fprintf(stderr, "DeleteService failed.\n");
else
- printf("Service %s deleted successfully.\n", service_name);
+ printf("Service " SQUIDSBUFPH " deleted successfully.\n", SQUIDSBUFPRINT(service_name));
CloseServiceHandle(schService);
}
void
WIN32_SetServiceCommandLine()
{
- if (!service_name)
- service_name = xstrdup(APP_SHORTNAME);
+ if (service_name.isEmpty())
+ service_name = SBuf(APP_SHORTNAME);
- strcat(REGKEY, service_name);
+ const char *service = servie_name.c_str();
+ strcat(REGKEY, service);
- keys[4] = service_name;
+ keys[4] = service;
/* Now store the Service Command Line in the registry */
WIN32_StoreKey(COMMANDLINE, REG_SZ, (unsigned char *) WIN32_Command_Line, strlen(WIN32_Command_Line) + 1);
char szPath[512];
int lenpath;
- if (!service_name)
- service_name = xstrdup(APP_SHORTNAME);
+ if (service_name.isEmpty())
+ service_name = SBuf(APP_SHORTNAME);
- strcat(REGKEY, service_name);
+ const char *service = service_name.c_str();
+ strcat(REGKEY, service);
- keys[4] = service_name;
+ keys[4] = service;
if ((lenpath = GetModuleFileName(NULL, ServicePath, 512)) == 0) {
fprintf(stderr, "Can't get executable path\n");
exit(1);
}
- snprintf(szPath, sizeof(szPath), "%s %s:%s", ServicePath, _WIN_SQUID_SERVICE_OPTION, service_name);
+ snprintf(szPath, sizeof(szPath), "%s %s:" SQUIDSBUFPH, ServicePath, _WIN_SQUID_SERVICE_OPTION, SQUIDSBUFPRINT(service_name));
schSCManager = OpenSCManager(NULL, /* machine (NULL == local) */
NULL, /* database (NULL == default) */
SC_MANAGER_ALL_ACCESS /* access required */
exit(1);
} else {
schService = CreateService(schSCManager, /* SCManager database */
- service_name, /* name of service */
- service_name, /* name to display */
+ service, /* name of service */
+ service, /* name to display */
SERVICE_ALL_ACCESS, /* desired access */
SERVICE_WIN32_OWN_PROCESS, /* service type */
SERVICE_AUTO_START, /* start type */
WIN32_StoreKey(CONFIGFILE, REG_SZ, (unsigned char *) ConfigFile, strlen(ConfigFile) + 1);
printf("Squid Cache version %s for %s\n", version_string, CONFIG_HOST_TYPE);
- printf("installed successfully as %s Windows System Service.\n", service_name);
+ printf("installed successfully as " SQUIDSBUFPH " Windows System Service.\n", SQUIDSBUFPRINT(service_name));
printf("To run, start it from the Services Applet of Control Panel.\n");
printf("Don't forget to edit squid.conf before starting it.\n\n");
} else {
SC_HANDLE schService;
SC_HANDLE schSCManager;
- if (!service_name)
- service_name = xstrdup(APP_SHORTNAME);
+ if (service_name.isEmpty())
+ service_name = SBuf(APP_SHORTNAME);
schSCManager = OpenSCManager(NULL, /* machine (NULL == local) */
NULL, /* database (NULL == default) */
/* Open a handle to the service. */
schService = OpenService(schSCManager, /* SCManager database */
- service_name, /* name of service */
+ service_name.c_str(), /* name of service */
fdwAccess); /* specify access */
if (schService == NULL) {
- fprintf(stderr, "%s: ERROR: Could not open Service %s\n", APP_SHORTNAME, service_name);
+ fprintf(stderr, "%s: ERROR: Could not open Service " SQUIDSBUFPH "\n", APP_SHORTNAME, SQUIDSBUFPRINT(service_name));
exit(1);
} else {
/* Send a control value to the service. */
if (!ControlService(schService, /* handle of service */
fdwControl, /* control value to send */
&ssStatus)) { /* address of status info */
- fprintf(stderr, "%s: ERROR: Could not Control Service %s\n",
- APP_SHORTNAME, service_name);
+ fprintf(stderr, "%s: ERROR: Could not Control Service " SQUIDSBUFPH "\n",
+ APP_SHORTNAME, SQUIDSBUFPRINT(service_name));
exit(1);
} else {
/* Print the service status. */
- printf("\nStatus of %s Service:\n", service_name);
+ printf("\nStatus of " SQUIDSBUFPH " Service:\n", SQUIDSBUFPRINT(service_name));
printf(" Service Type: 0x%lx\n", ssStatus.dwServiceType);
printf(" Current State: 0x%lx\n", ssStatus.dwCurrentState);
printf(" Controls Accepted: 0x%lx\n", ssStatus.dwControlsAccepted);
return 1;
}
- service_name = xstrdup(c+1);
- DispatchTable[0].lpServiceName=service_name;
- strcat(REGKEY, service_name);
- keys[4] = service_name;
+ service_name = SBuf(c+1);
+ const char *service = service_name.c_str();
+ DispatchTable[0].lpServiceName=service;
+ strcat(REGKEY, service);
+ keys[4] = service;
if (!StartServiceCtrlDispatcher(DispatchTable)) {
fprintf(stderr, "StartServiceCtrlDispatcher error = %ld\n",
#include "MemPool.h"
#include "mime.h"
#include "neighbors.h"
+#include "parser/Tokenizer.h"
#include "pconn.h"
#include "peer_sourcehash.h"
#include "peer_userhash.h"
/** \par n
* Set global option opt_signal_service (to true).
* Stores the additional parameter given in global service_name */
- // XXX: verify that the new name has ONLY alphanumeric characters
- xfree(service_name);
- service_name = xstrdup(optarg);
- opt_signal_service = true;
+ if (optarg || *optarg == '\0') {
+ const SBuf t(optarg);
+ ::Parser::Tokenizer tok(t);
+ const CharacterSet chr = CharacterSet::ALPHA+CharacterSet::DIGIT;
+ if (!tok.prefix(service_name, chr) || !tok.atEnd())
+ fatalf("Expected alphanumeric service name for the -n option but got: " SQUIDSBUFPH, SQUIDSBUFPRINT(service_name));
+ if (service_name.length() > 32)
+ fatalf("Service name (-n option) must be limited to 32 characters but got %u", service_name.length());
+ opt_signal_service = true;
+ } else {
+ fatal("A service name is required for the -n option");
+ }
break;
#if USE_WIN32_SERVICE
/** \par v
* Display squid version and build information. Then exit. */
printf("Squid Cache: Version %s\n" ,version_string);
- printf("Service Name: %s\n", service_name);
+ printf("Service Name: " SQUIDSBUFPH "\n", SQUIDSBUFPRINT(service_name));
if (strlen(SQUID_BUILD_INFO))
printf("%s\n",SQUID_BUILD_INFO);
printf( "configure options: %s\n", SQUID_CONFIGURE_OPTIONS);