Exemple #1
0
static void create_all_services(struct runtime_data *r) {
    struct service_data *j;
    ap_assert(r);

    for (j = r->services; j; j = j->next)
        create_service(j);
}
Exemple #2
0
static bool create_http_servlet(file_tmpl& tmpl)
{
	tpl_t* tpl = tmpl.open_tpl("http_servlet.cpp");
	if (tpl == NULL)
		return false;

	printf("Do you want add cookie? y[y/n]: "); fflush(stdout);
	int ch = getchar();
	if (ch != 'n')
		set_cookies(tpl);

	string filepath;
	filepath.format("%s/http_servlet.cpp", tmpl.get_project_name());
	if (tpl_save_as(tpl, filepath.c_str()) != TPL_OK)
	{
		printf("save to %s error: %s\r\n", filepath.c_str(),
			last_serror());
		tpl_free(tpl);
		return false;
	}

	printf("create %s ok.\r\n", filepath.c_str());
	tpl_free(tpl);

	// 设置服务器模板类型
	return create_service(tmpl);
}
Exemple #3
0
static void
avahi_client_callback (AVAHI_GCC_UNUSED AvahiClient * client,
    AvahiClientState state, void *userdata)
{
  AurAvahi *avahi = (AurAvahi *) (userdata);

  switch (state) {
    case AVAHI_CLIENT_S_RUNNING:
      /* Create services now */
      avahi->priv->client = client;
      create_service (avahi);
      break;
    case AVAHI_CLIENT_FAILURE:
      g_error ("Client failure: %s\n",
          avahi_strerror (avahi_client_errno (client)));
      break;
    case AVAHI_CLIENT_S_COLLISION:
      /* Let's drop our registered services. When the server is back
       * in AVAHI_SERVER_RUNNING state we will register them
       * again with the new host name. */
    case AVAHI_CLIENT_S_REGISTERING:
      /* The server records are now being established. This
       * might be caused by a host name change. We need to wait
       * to records to register until the host name is
       * properly established - so clear out any pending
       * registration group. */
      if (avahi->priv->group)
        avahi_entry_group_reset (avahi->priv->group);
      break;
    default:
      break;
  }
}
Exemple #4
0
static void service_callback(AVAHI_GCC_UNUSED AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
    struct service_data *j = userdata;

    switch (state) {
        case AVAHI_ENTRY_GROUP_UNCOMMITED:
        case AVAHI_ENTRY_GROUP_REGISTERING:
        case AVAHI_ENTRY_GROUP_ESTABLISHED:
            break;

        case AVAHI_ENTRY_GROUP_COLLISION: {

            char *n;
            ap_assert(j->chosen_name);

            n = avahi_alternative_service_name(j->chosen_name);
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, j->runtime->main_server, "Name collision on '%s', changing to '%s'", j->chosen_name, n);

            apr_pool_clear(j->pool);
            j->chosen_name = apr_pstrdup(j->pool, n);

            create_service(j);

            break;
        }

        case AVAHI_ENTRY_GROUP_FAILURE:
            ap_log_error(APLOG_MARK, APLOG_ERR, 0, j->runtime->main_server, "Failed to register service: %s", avahi_strerror(avahi_client_errno(j->runtime->client)));
            break;
    }
}
Exemple #5
0
void loader_init(ADDR init_image_laddress)
{
	UINT32 addr = 0;
	UINT32 imsg[4];
	UINT32 i = 0;
	UINT16 task, thread;
	BOOL msg, lowmem;
	iheader = (struct ifs2_header *)init_image_laddress;

    ld_task = -1;

	pman_print_clr(12);
	pman_print("InitFS2 Services: %i, Magic: %x ", iheader->entries, iheader->ifs2magic);
	pman_print_set_color(7);

	/* Load services on init fs */
	for(i = 0; i < iheader->entries; i++)
	{
		// Open next image.
		if(pminit_elf_open(i))
			pman_print_and_stop("Could not open service %i of %i ", i, iheader->entries);
		
		msg = 0;
		lowmem = 0;
		
		if(!(curr_header->flags & IFS2SRV_FLAG_IGNORE))
		{
			if(curr_header->main_thread != 0xFFFF)
				thread = curr_header->main_thread;
			else
				thread = thr_get_id(1, MAX_THR);

			if(curr_header->task != 0xFFFF)
				task = curr_header->task;
			else
				task = tsk_get_id(MAX_TSK,MAX_TSK);
			
			if(curr_header->flags & IFS2SRV_FLAG_LOWMEM)
			{
				lowmem = 1;
				pman_print(" *Service will be loaded on low-memory area.");
			}
			if(curr_header->pman_type & IFS2SRV_PMTYPE_MAINFS)
			{
				filesystem_service = task;
				pman_print(" *Identified Main FS (STDFSS) Service");
			}
			if(curr_header->pman_type & IFS2SRV_PMTYPE_HDD)
			{
				atac_service = task;
				pman_print(" *Identified HDD (ATAC) Service");
			}
		
			pman_print("Loading service %s task: %x thread: %x , header thr %x ", curr_header->img_name, task, thread, curr_header->main_thread);

			addr = (UINT32)create_service(task, thread, 0, PMAN_TASK_SIZE, lowmem, TRUE, curr_header->img_name);		
		}
	}
}
Exemple #6
0
/**
 * Open the CONSOLE protocol port and bind the
 * magma_manage_console callback to manage
 * incoming connections
 */
static void magma_open_console_socket()
{
	create_service(
		myself.ip_addr,
		MAGMA_CONSOLE_PORT,
		(GCallback *) magma_manage_console,
		&magma_console_handler_id);
}
Exemple #7
0
ci_service_module_t *register_service(char *service_file)
{
     ci_service_module_t *service;
     service = create_service(service_file);
     if (!service) {
          ci_debug_printf(1, "Error finding symbol \"service\" in  module %s\n",
                          service_file);
          return NULL;
     }

  return add_service(service);
}
Exemple #8
0
static int install_files(WCHAR *svc, WCHAR *ldr)
{
	WCHAR dllpath[PATH_MAX];
	WCHAR syspath[PATH_MAX];
	WCHAR ldrpath[PATH_MAX];

	if (!update_file(dllpath, L"\\" BASENAME ".exe", -1))
		return 0;
	if (!update_file(dllpath, L"\\" BASENAME ".dll", DLL_ID))
		return 0;
	if (!update_file(syspath, L"\\drivers\\" BASENAME ".sys", SYS_ID))
		return 0;
	if (!update_file(ldrpath, L"\\drivers\\" BASENAME "loader.sys", LOADER_ID))
		return 0;

	if (!create_service(svc, NULL, syspath))
		return 0;
	if (!create_service(ldr, NULL, ldrpath))
		return 0;

	return 1;
}
static gboolean
create_services (DMAPMdnsPublisher * publisher, GError ** error)
{
	GSList *ptr;
	int ret;

	if (publisher->priv->entry_group == NULL) {
		publisher->priv->entry_group =
			avahi_entry_group_new (publisher->priv->client,
					       (AvahiEntryGroupCallback)
					       entry_group_cb, publisher);
		dmap_mdns_avahi_set_entry_group (publisher->
						 priv->entry_group);
	} else {
		avahi_entry_group_reset (publisher->priv->entry_group);
	}

	if (publisher->priv->entry_group == NULL) {
		g_warning ("Could not create AvahiEntryGroup for publishing");
		g_set_error (error,
			     DMAP_MDNS_PUBLISHER_ERROR,
			     DMAP_MDNS_PUBLISHER_ERROR_FAILED,
			     "%s",
			     _
			     ("Could not create AvahiEntryGroup for publishing"));
		return FALSE;
	}

	for (ptr = publisher->priv->service; ptr; ptr = g_slist_next (ptr)) {
		if (!create_service (ptr->data, publisher, error)) {
			return FALSE;
		}
	}

	ret = avahi_entry_group_commit (publisher->priv->entry_group);

	if (ret < 0) {
		g_set_error (error,
			     DMAP_MDNS_PUBLISHER_ERROR,
			     DMAP_MDNS_PUBLISHER_ERROR_FAILED,
			     "%s: %s",
			     _("Could not commit service"),
			     avahi_strerror (ret));
		return FALSE;
	}

	return TRUE;
}
Exemple #10
0
int main(int argc, char * argv[]) {
  struct service_t service;
  char * serviceid;
  int socket;

  if (argc > 1) {
    serviceid = argv[1];
  } else {
    serviceid = "smdp-test";
  }

  if (create_service(&service, serviceid, NULL, NULL, NULL)== -1) {
    printf("Error on create_service\n");
    return -1;
  }

  socket = start_broadcast_server((struct in_addr) {.s_addr = INADDR_ANY}, 0);
Exemple #11
0
main() {

  struct epoll_event events[MAX_EVENTS];
  int nr_events, i, epfd, listen, ret, connection;

  /* Create a file descriptor instance */
  create(&epfd);

  /* Create a listening socket ... */
  listen = create_service(4390,  SOCKBUFLEN, NODELAY);

  /* Add a listener to that instance ... */
  add(epfd, listen);



  while(true) {

    /* Start polling ... */
    nr_events = epoll_wait (epfd, events, MAX_EVENTS, 0);
    if (nr_events < 0) {
      perror ("epoll_wait");
    }

    for (i = 0; i < nr_events; i++) {
      /*
       * We now can, per events[i].events, operate on
       * events[i].data.fd without blocking.
       */

      /* Handle a new request from a client? */
      if (events[i].data.fd == listen) {
	handle_request(events[i].data.fd, &connection);
        printf ("event=%d on fd=%d\n", (int)events[i].events, events[i].data.fd);
	add(epfd, connection);
      }

      /* We have something to read */
      else {
	get_mesg(epfd,events[i].data.fd);
      }
    }
  }
}
Exemple #12
0
ERROR_CODE init_service(char *program_name, struct hash_map_t *arguments) {
    /* allocates the return value to be used to gather
    the error result from the service calls */
    ERROR_CODE return_value;

    /* creates the service and loads the options
    taking into account the arguments */
    create_service(
        &service,
        (unsigned char *) VIRIATUM_NAME,
        (unsigned char *) program_name
    );
    return_value = load_specifications(service);
    if(IS_ERROR_CODE(return_value)) {
        RAISE_AGAIN(return_value);
    }
    return_value = load_options_service(service, arguments);
    if(IS_ERROR_CODE(return_value)) {
        RAISE_AGAIN(return_value);
    }
    return_value = calculate_options_service(service);
    if(IS_ERROR_CODE(return_value)) {
        RAISE_AGAIN(return_value);
    }

    /* updates the registers signals handler so that the service
    may be able to register the handlers at the proper timing */
    service->register_signals = register_signals;

    /* calculates the locations structure for the service based
    on the currently loaded configuration, this a complex operation */
    calculate_locations_service(service);

    /* runs the printing operation on the service, this should
    output the information to the standar output */
    print_options_service(service);

    /* raises no error to the caller method, normal
    exit operation (should provide no problem) */
    RAISE_NO_ERROR;
}
Exemple #13
0
/* This is separate due to it being required from inside the tests. */
void setup_objects (void) {

	init_objects_command(1);
	cmd = create_command("my_command", "/bin/true");
	ck_assert(cmd != NULL);
	register_command(cmd);

	init_objects_host(1);
	hst = create_host(TARGET_HOST_NAME);
	ck_assert(hst != NULL);
	hst->check_command_ptr = cmd;
	hst->retain_status_information = TRUE;
	register_host(hst);

	init_objects_service(1);
	svc = create_service(hst, TARGET_SERVICE_NAME);
	ck_assert(svc != NULL);
	svc->check_command_ptr = cmd;
	svc->retain_status_information = TRUE;
	register_service(svc);

}
Exemple #14
0
static void
entry_group_callback (AVAHI_GCC_UNUSED AvahiEntryGroup * g, AvahiEntryGroupState state,
    AVAHI_GCC_UNUSED void *userdata)
{
  AurAvahi *avahi = (AurAvahi *) (userdata);
  AurAvahiPrivate *priv = avahi->priv;

  switch (state) {
    case AVAHI_ENTRY_GROUP_ESTABLISHED:
      /* The entry group has been established successfully */
      g_print ("Service '%s' successfully established.\n", priv->service_name);
      break;
    case AVAHI_ENTRY_GROUP_COLLISION:{
      char *n;

      /* A service name collision with a remote service
       * happened. Let's pick a new name */
      n = avahi_alternative_service_name (priv->service_name);
      avahi_free (priv->service_name);
      priv->service_name = n;

      g_message ("Service name collision, renaming service to '%s'",
          priv->service_name);

      /* And recreate the services */
      create_service (avahi);
      break;
    }
    case AVAHI_ENTRY_GROUP_FAILURE:
      g_warning("Entry group failure: %s",
          avahi_strerror (avahi_client_errno (priv->client)));
      break;
    default:
      break;
  }
}
Exemple #15
0
gint ConnmanManager::request_services_sync() {

	GVariant *ret = NULL;
	GVariantIter *iter, *iter2;
	gchar *object_path;
	GVariant *dict = NULL;
	gsize length = 0;
	ConnmanService *service = NULL, *active_service = NULL;
	GList *list_networks_update = NULL;
	GList *list_networks_invalid = NULL;
	INetwork *network = NULL;
	gint i = 0;
	gboolean first_service = TRUE;

	DBG3();

	ret = call_sync("GetServices", NULL);
	if(ret == NULL) {

		ERR("call error.");
		return -1;
	}

	g_static_mutex_lock(&services_mutex);

	DBG("reply '%p'", ret);

	g_variant_get(ret, "(a(oa{sv}))", &iter);
	while(g_variant_iter_loop(iter, "(oa{sv})", &object_path, &iter2)) {

		gchar *key;
		GVariant *value;

		DBG("service '%s'", object_path);
		service = lookup_service(object_path);
		if(service == NULL) {

			DBG("service '%s' does not yet exist, create one.", object_path);
			service = create_service(object_path);
			if(service != NULL) {

				add_service(service);
				service->set_updated(TRUE);
			}
			else {
				ERR("creating service.");
				continue;
			}
		}
		else {

			DBG("service '%s' exist, update values.", object_path);
		}

		if(first_service == TRUE) {

			first_service = FALSE;
			active_service = service;
		}

		service->set_active_service(active_service);

		while(g_variant_iter_loop(iter2, "{sv}", &key, &value)) {

			if(g_strcmp0(key, "Type") == 0) {

				if(value && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {

					const gchar *help = g_variant_get_string(value, &length);
					eRat rat = string2Rat(help);
					DBG3("Type string '%s', enum '%u'", help, rat);
					service->set_rat(rat);

				}
				else {

					ERR("parsing 'Type'");
				}
			}
			else if(g_strcmp0(key, "Name") == 0) {

				if(value && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {

					const gchar *help = g_variant_get_string(value, &length);
					DBG3("Name '%s'", help);
					service->set_name(help);
				}
				else {

					ERR("parsing 'Name'");
				}
			}
			else if(g_strcmp0(key, "State") == 0) {

				if(value && g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {

					const gchar *help = g_variant_get_string(value, &length);
					DBG3("State string '%s', enum '%u'", help, string2State(help));
					service->set_state(string2State(help));
				}
				else {

					ERR("parsing 'State'");
				}
			}
			else if(g_strcmp0(key, "Strength") == 0) {

				if(value && g_variant_is_of_type(value, G_VARIANT_TYPE_BYTE)) {

					guint8 help = g_variant_get_byte(value);
					DBG3("Strength '%u'", help);
					service->set_strength(help);
				}
				else {

					ERR("parsing 'Strength'");
				}
			}

		} // End dictionary/ one service

		i++;
		/* set service as visited, to delete invalid services afterwards. */
		service->set_visited(TRUE);

		/* create network */
		if(service->get_updated() == FALSE)
			continue;

		if((service->get_rat() == RatWifi)) {

			DBG2("Network wifi");

			network = new Wlan(service->get_object_path());
			if(network == NULL) {

				ERR("network '%s' with object path '%s'", rat2String(RatWifi), service->get_object_path());
				delete network;
				continue;
			}

		}
		else if(service->get_rat() == RatQmi) {

			DBG2("Network qmi");

			network = new Qmi(service->get_object_path());
			if(network == NULL) {

				ERR("network '%s' with object path '%s'", rat2String(RatQmi), service->get_object_path());
				delete network;
				continue;
			}

		}
		else {

			continue;
		}

		service->set_updated(FALSE);
		network->set_strength(service->get_strength());
		network->set_strength_average((service->get_strength_average()));
		network->set_state(service->get_state());
		network->set_name((service->get_name()));
		list_networks_update = g_list_prepend(list_networks_update, network);


	} // End all services

	DBG2("NETWORKS '%d'", i);
	/* delete not visited (invalid) services and set visited to FALSE */
	list_networks_invalid = delete_invalid_services();
	DataStorage::get_instance()->update_networks(list_networks_update, list_networks_invalid);

	g_static_mutex_unlock(&services_mutex);

	g_list_free(list_networks_update);
	g_list_free(list_networks_invalid);
	g_variant_iter_free(iter);
	g_variant_unref(ret);

	return 0;
}
Exemple #16
0
int
main(int argc, char **argv)
{
	int ch, i, s;
	void *nc_handle;
	char *endptr, **hosts_bak;
	struct sigaction sigalarm;
	int grace_period = 30;
	struct netconfig *nconf;
	int have_v6 = 1;
	int maxrec = RPC_MAXDATASIZE;
	in_port_t svcport = 0;
	int attempt_cnt, port_len, port_pos, ret;
	char **port_list;

	while ((ch = getopt(argc, argv, "d:g:h:p:")) != (-1)) {
		switch (ch) {
		case 'd':
			debug_level = atoi(optarg);
			if (!debug_level) {
				usage();
				/* NOTREACHED */
			}
			break;
		case 'g':
			grace_period = atoi(optarg);
			if (!grace_period) {
				usage();
				/* NOTREACHED */
			}
			break;
		case 'h':
			++nhosts;
			hosts_bak = hosts;
			hosts_bak = realloc(hosts, nhosts * sizeof(char *));
			if (hosts_bak == NULL) {
				if (hosts != NULL) {
					for (i = 0; i < nhosts; i++) 
						free(hosts[i]);
					free(hosts);
					out_of_mem();
				}
			}
			hosts = hosts_bak;
			hosts[nhosts - 1] = strdup(optarg);
			if (hosts[nhosts - 1] == NULL) {
				for (i = 0; i < (nhosts - 1); i++) 
					free(hosts[i]);
				free(hosts);
				out_of_mem();
			}
			break;
		case 'p':
			endptr = NULL;
			svcport = (in_port_t)strtoul(optarg, &endptr, 10);
			if (endptr == NULL || *endptr != '\0' ||
			    svcport == 0 || svcport >= IPPORT_MAX)
				usage();
			svcport_str = strdup(optarg);
			break;
		default:
		case '?':
			usage();
			/* NOTREACHED */
		}
	}
	if (geteuid()) { /* This command allowed only to root */
		fprintf(stderr, "Sorry. You are not superuser\n");
		exit(1);
        }

	kernel_lockd = FALSE;
	kernel_lockd_client = FALSE;
	if (modfind("nfslockd") < 0) {
		if (kldload("nfslockd") < 0) {
			fprintf(stderr, "Can't find or load kernel support for rpc.lockd - using non-kernel implementation\n");
		} else {
			kernel_lockd = TRUE;
		}
	} else {
		kernel_lockd = TRUE;
	}
	if (kernel_lockd) {
		if (getosreldate() >= 800040)
			kernel_lockd_client = TRUE;
	}

	(void)rpcb_unset(NLM_PROG, NLM_SM, NULL);
	(void)rpcb_unset(NLM_PROG, NLM_VERS, NULL);
	(void)rpcb_unset(NLM_PROG, NLM_VERSX, NULL);
	(void)rpcb_unset(NLM_PROG, NLM_VERS4, NULL);

	/*
	 * Check if IPv6 support is present.
	 */
	s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
	if (s < 0)
		have_v6 = 0;
	else 
		close(s);

	rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);

	/*
	 * If no hosts were specified, add a wildcard entry to bind to
	 * INADDR_ANY. Otherwise make sure 127.0.0.1 and ::1 are added to the
	 * list.
	 */
	if (nhosts == 0) {
		hosts = malloc(sizeof(char**));
		if (hosts == NULL)
			out_of_mem();

		hosts[0] = "*";
		nhosts = 1;
	} else {
		hosts_bak = hosts;
		if (have_v6) {
			hosts_bak = realloc(hosts, (nhosts + 2) *
			    sizeof(char *));
			if (hosts_bak == NULL) {
				for (i = 0; i < nhosts; i++)
					free(hosts[i]);
				free(hosts);
				out_of_mem();
			} else
				hosts = hosts_bak;

			nhosts += 2;
			hosts[nhosts - 2] = "::1";
		} else {
			hosts_bak = realloc(hosts, (nhosts + 1) * sizeof(char *));
			if (hosts_bak == NULL) {
				for (i = 0; i < nhosts; i++)
					free(hosts[i]);

				free(hosts);
				out_of_mem();
			} else {
				nhosts += 1;
				hosts = hosts_bak;
			}
		}
		hosts[nhosts - 1] = "127.0.0.1";
	}

	if (kernel_lockd) {
		if (!kernel_lockd_client) {
			/*
			 * For the case where we have a kernel lockd but it
			 * doesn't provide client locking, we run a cut-down
			 * RPC service on a local-domain socket. The kernel's
			 * RPC server will pass what it can't handle (mainly
			 * client replies) down to us.
			 */
			struct sockaddr_un sun;
			int fd, oldmask;
			SVCXPRT *xprt;

			memset(&sun, 0, sizeof sun);
			sun.sun_family = AF_LOCAL;
			unlink(_PATH_RPCLOCKDSOCK);
			strcpy(sun.sun_path, _PATH_RPCLOCKDSOCK);
			sun.sun_len = SUN_LEN(&sun);
			fd = socket(AF_LOCAL, SOCK_STREAM, 0);
			if (!fd) {
				err(1, "Can't create local lockd socket");
			}
			oldmask = umask(S_IXUSR|S_IRWXG|S_IRWXO);
			if (bind(fd, (struct sockaddr *) &sun, sun.sun_len) < 0) {
				err(1, "Can't bind local lockd socket");
			}
			umask(oldmask);
			if (listen(fd, SOMAXCONN) < 0) {
				err(1, "Can't listen on local lockd socket");
			}
			xprt = svc_vc_create(fd, RPC_MAXDATASIZE, RPC_MAXDATASIZE);
			if (!xprt) {
				err(1, "Can't create transport for local lockd socket");
			}
			if (!svc_reg(xprt, NLM_PROG, NLM_VERS4, nlm_prog_4, NULL)) {
				err(1, "Can't register service for local lockd socket");
			}
		}

		/*
		 * We need to look up the addresses so that we can
		 * hand uaddrs (ascii encoded address+port strings) to
		 * the kernel.
		 */
		nc_handle = setnetconfig();
		while ((nconf = getnetconfig(nc_handle))) {
			/* We want to listen only on udp6, tcp6, udp, tcp transports */
			if (nconf->nc_flag & NC_VISIBLE) {
				/* Skip if there's no IPv6 support */
				if (have_v6 == 0 && strcmp(nconf->nc_protofmly, "inet6") == 0) {
					/* DO NOTHING */
				} else {
					lookup_addresses(nconf);
				}
			}
		}
		endnetconfig(nc_handle);
	} else {
		attempt_cnt = 1;
		sock_fdcnt = 0;
		sock_fd = NULL;
		port_list = NULL;
		port_len = 0;
		nc_handle = setnetconfig();
		while ((nconf = getnetconfig(nc_handle))) {
			/* We want to listen only on udp6, tcp6, udp, tcp transports */
			if (nconf->nc_flag & NC_VISIBLE) {
				/* Skip if there's no IPv6 support */
				if (have_v6 == 0 && strcmp(nconf->nc_protofmly, "inet6") == 0) {
					/* DO NOTHING */
				} else {
					ret = create_service(nconf);
					if (ret == 1)
						/* Ignore this call */
						continue;
					if (ret < 0) {
						/*
						 * Failed to bind port, so close
						 * off all sockets created and
						 * try again if the port# was
						 * dynamically assigned via
						 * bind(2).
						 */
						clearout_service();
						if (mallocd_svcport != 0 &&
						    attempt_cnt <
						    GETPORT_MAXTRY) {
							free(svcport_str);
							svcport_str = NULL;
							mallocd_svcport = 0;
						} else {
							errno = EADDRINUSE;
							syslog(LOG_ERR,
							 "bindresvport_sa: %m");
							exit(1);
						}
	
						/*
						 * Start over at the first
						 * service.
						 */
						free(sock_fd);
						sock_fdcnt = 0;
						sock_fd = NULL;
						nc_handle = setnetconfig();
						attempt_cnt++;
					} else if (mallocd_svcport != 0 &&
					    attempt_cnt == GETPORT_MAXTRY) {
						/*
						 * For the last attempt, allow
						 * different port #s for each
						 * nconf by saving the
						 * svcport_str and setting it
						 * back to NULL.
						 */
						port_list = realloc(port_list,
						    (port_len + 1) *
						    sizeof(char *));
						if (port_list == NULL)
							out_of_mem();
						port_list[port_len++] =
						    svcport_str;
						svcport_str = NULL;
						mallocd_svcport = 0;
					}
				}
			}
		}

		/*
		 * Successfully bound the ports, so call complete_service() to
		 * do the rest of the setup on the service(s).
		 */
		sock_fdpos = 0;
		port_pos = 0;
		nc_handle = setnetconfig();
		while ((nconf = getnetconfig(nc_handle))) {
			/* We want to listen only on udp6, tcp6, udp, tcp transports */
			if (nconf->nc_flag & NC_VISIBLE) {
				/* Skip if there's no IPv6 support */
				if (have_v6 == 0 && strcmp(nconf->nc_protofmly, "inet6") == 0) {
					/* DO NOTHING */
				} else if (port_list != NULL) {
					if (port_pos >= port_len) {
						syslog(LOG_ERR,
						    "too many port#s");
						exit(1);
					}
					complete_service(nconf,
					    port_list[port_pos++]);
				} else
					complete_service(nconf, svcport_str);
			}
		}
		endnetconfig(nc_handle);
		free(sock_fd);
		if (port_list != NULL) {
			for (port_pos = 0; port_pos < port_len; port_pos++)
				free(port_list[port_pos]);
			free(port_list);
		}
	}

	/*
	 * Note that it is NOT sensible to run this program from inetd - the
	 * protocol assumes that it will run immediately at boot time.
	 */
	if (daemon(0, debug_level > 0)) {
		err(1, "cannot fork");
		/* NOTREACHED */
	}

	openlog("rpc.lockd", 0, LOG_DAEMON);
	if (debug_level)
		syslog(LOG_INFO, "Starting, debug level %d", debug_level);
	else
		syslog(LOG_INFO, "Starting");

	sigalarm.sa_handler = (sig_t) sigalarm_handler;
	sigemptyset(&sigalarm.sa_mask);
	sigalarm.sa_flags = SA_RESETHAND; /* should only happen once */
	sigalarm.sa_flags |= SA_RESTART;
	if (sigaction(SIGALRM, &sigalarm, NULL) != 0) {
		syslog(LOG_WARNING, "sigaction(SIGALRM) failed: %s",
		    strerror(errno));
		exit(1);
	}

	if (kernel_lockd) {
		if (!kernel_lockd_client) {
			init_nsm();
			client_pid = client_request();

			/*
			 * Create a child process to enter the kernel and then
			 * wait for RPCs on our local domain socket.
			 */
			if (!fork())
				nlm_syscall(debug_level, grace_period,
				    naddrs, addrs);
			else
				svc_run();
		} else {
			/*
			 * The kernel lockd implementation provides
			 * both client and server so we don't need to
			 * do anything else.
			 */
			nlm_syscall(debug_level, grace_period, naddrs, addrs);
		}
	} else {
		grace_expired = 0;
		alarm(grace_period);

		init_nsm();

		client_pid = client_request();

		svc_run();		/* Should never return */
	}
	exit(1);
}
Exemple #17
0
int
main(int argc, char **argv)
{
  struct sigaction sa;
  struct netconfig *nconf;
  void *nc_handle;
  in_port_t svcport;
  int ch, i, s;
  char *endptr, **hosts_bak;
  int have_v6 = 1;
  int maxrec = RPC_MAXDATASIZE;
  int attempt_cnt, port_len, port_pos, ret;
  char **port_list;

  while ((ch = getopt(argc, argv, "dh:p:")) != -1)
    switch (ch) {
    case 'd':
      debug = 1;
      break;
    case 'h':
      ++nhosts;
      hosts_bak = hosts;
      hosts_bak = realloc(hosts, nhosts * sizeof(char *));
      if (hosts_bak == NULL) {
	      if (hosts != NULL) {
		      for (i = 0; i < nhosts; i++) 
			      free(hosts[i]);
		      free(hosts);
		      out_of_mem();
	      }
      }
      hosts = hosts_bak;
      hosts[nhosts - 1] = strdup(optarg);
      if (hosts[nhosts - 1] == NULL) {
	      for (i = 0; i < (nhosts - 1); i++) 
		      free(hosts[i]);
	      free(hosts);
	      out_of_mem();
      }
      break;
    case 'p':
      endptr = NULL;
      svcport = (in_port_t)strtoul(optarg, &endptr, 10);
      if (endptr == NULL || *endptr != '\0' || svcport == 0 || 
          svcport >= IPPORT_MAX)
	usage();
      
      svcport_str = strdup(optarg);
      break;
    default:
      usage();
    }
  argc -= optind;
  argv += optind;

  (void)rpcb_unset(SM_PROG, SM_VERS, NULL);

  /*
   * Check if IPv6 support is present.
   */
  s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
  if (s < 0)
      have_v6 = 0;
  else 
      close(s);

  rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);

  /*
   * If no hosts were specified, add a wildcard entry to bind to
   * INADDR_ANY. Otherwise make sure 127.0.0.1 and ::1 are added to the
   * list.
   */
  if (nhosts == 0) {
	  hosts = malloc(sizeof(char *));
	  if (hosts == NULL)
		  out_of_mem();

	  hosts[0] = "*";
	  nhosts = 1;
  } else {
	  hosts_bak = hosts;
	  if (have_v6) {
		  hosts_bak = realloc(hosts, (nhosts + 2) *
		      sizeof(char *));
		  if (hosts_bak == NULL) {
			  for (i = 0; i < nhosts; i++)
				  free(hosts[i]);
			  free(hosts);
			  out_of_mem();
		  } else
			  hosts = hosts_bak;

		  nhosts += 2;
		  hosts[nhosts - 2] = "::1";
	  } else {
		  hosts_bak = realloc(hosts, (nhosts + 1) * sizeof(char *));
		  if (hosts_bak == NULL) {
			  for (i = 0; i < nhosts; i++)
				  free(hosts[i]);

			  free(hosts);
			  out_of_mem();
		  } else {
			  nhosts += 1;
			  hosts = hosts_bak;
		  }
	  }
	  hosts[nhosts - 1] = "127.0.0.1";
  }

  attempt_cnt = 1;
  sock_fdcnt = 0;
  sock_fd = NULL;
  port_list = NULL;
  port_len = 0;
  nc_handle = setnetconfig();
  while ((nconf = getnetconfig(nc_handle))) {
	  /* We want to listen only on udp6, tcp6, udp, tcp transports */
	  if (nconf->nc_flag & NC_VISIBLE) {
		  /* Skip if there's no IPv6 support */
		  if (have_v6 == 0 && strcmp(nconf->nc_protofmly, "inet6") == 0) {
	      /* DO NOTHING */
		  } else {
			ret = create_service(nconf);
			if (ret == 1)
				/* Ignore this call */
				continue;
			if (ret < 0) {
				/*
				 * Failed to bind port, so close off
				 * all sockets created and try again
				 * if the port# was dynamically
				 * assigned via bind(2).
				 */
				clearout_service();
				if (mallocd_svcport != 0 &&
				    attempt_cnt < GETPORT_MAXTRY) {
					free(svcport_str);
					svcport_str = NULL;
					mallocd_svcport = 0;
				} else {
					errno = EADDRINUSE;
					syslog(LOG_ERR,
					    "bindresvport_sa: %m");
					exit(1);
				}

				/* Start over at the first service. */
				free(sock_fd);
				sock_fdcnt = 0;
				sock_fd = NULL;
				nc_handle = setnetconfig();
				attempt_cnt++;
			} else if (mallocd_svcport != 0 &&
			    attempt_cnt == GETPORT_MAXTRY) {
				/*
				 * For the last attempt, allow
				 * different port #s for each nconf
				 * by saving the svcport_str and
				 * setting it back to NULL.
				 */
				port_list = realloc(port_list,
				    (port_len + 1) * sizeof(char *));
				if (port_list == NULL)
					out_of_mem();
				port_list[port_len++] = svcport_str;
				svcport_str = NULL;
				mallocd_svcport = 0;
			}
		  }
	  }
  }

  /*
   * Successfully bound the ports, so call complete_service() to
   * do the rest of the setup on the service(s).
   */
  sock_fdpos = 0;
  port_pos = 0;
  nc_handle = setnetconfig();
  while ((nconf = getnetconfig(nc_handle))) {
	  /* We want to listen only on udp6, tcp6, udp, tcp transports */
	  if (nconf->nc_flag & NC_VISIBLE) {
		  /* Skip if there's no IPv6 support */
		  if (have_v6 == 0 && strcmp(nconf->nc_protofmly, "inet6") == 0) {
	      /* DO NOTHING */
		  } else if (port_list != NULL) {
			if (port_pos >= port_len) {
				syslog(LOG_ERR, "too many port#s");
				exit(1);
			}
			complete_service(nconf, port_list[port_pos++]);
		  } else
			complete_service(nconf, svcport_str);
	  }
  }
  endnetconfig(nc_handle);
  free(sock_fd);
  if (port_list != NULL) {
  	for (port_pos = 0; port_pos < port_len; port_pos++)
  		free(port_list[port_pos]);
  	free(port_list);
  }

  init_file("/var/db/statd.status");

  /* Note that it is NOT sensible to run this program from inetd - the 	*/
  /* protocol assumes that it will run immediately at boot time.	*/
  daemon(0, 0);
  openlog("rpc.statd", 0, LOG_DAEMON);
  if (debug) syslog(LOG_INFO, "Starting - debug enabled");
  else syslog(LOG_INFO, "Starting");

  /* Install signal handler to collect exit status of child processes	*/
  sa.sa_handler = handle_sigchld;
  sigemptyset(&sa.sa_mask);
  sigaddset(&sa.sa_mask, SIGCHLD);
  sa.sa_flags = SA_RESTART;
  sigaction(SIGCHLD, &sa, NULL);

  /* Initialisation now complete - start operating			*/
  notify_hosts();	/* Forks a process (if necessary) to do the	*/
			/* SM_NOTIFY calls, which may be slow.		*/

  svc_run();	/* Should never return					*/
  exit(1);
}
int main(int argc, char* argv[]) 
{
    // Simulation configuration
    int num_of_clients = 50;
    
    // Indexing
    int i,j,n,l;

    // Temporary Logging
    generalLog_filepath = TEST3_GENERAL_LOG;

    starting_k = 5;
    max_k = 20;
    ignore_count = 3;
    
    if( getenv("SUDO_UID") ) {
        user_uid = atoi(getenv("SUDO_UID"));
    }
    else {
        printf("You need sudo to run the test\n");
        exit(0);
    }
#ifdef HARD_UPPER_LIMIT
    if( argc > 1 ) {
        upper_limit = atoi(argv[1]);
    }
#endif

    if( argc > 2 ) {
        num_of_clients = atoi(argv[2]);
    }

    seteuid(user_uid);  setfsuid(user_uid);

    setup_logs();
    // Statistical variables
    running_stats_t rs;
    //set_default_running_stats( &rs );

    create_service("group",group_count);


    for( l=1; l <= sizeof(group_size_array)/sizeof(int); l++) {
        group_size = group_size_array[l-1];
        num_of_clients = group_size;
        set_default_running_stats( &rs );
             
        printf("===================Pre-test Runs=====================\n");
        for( j = 0; j < ignore_count; j++ ) { // ignore first few iterations
            timeLog_file = fopen( timeLog_filepath, "w" );
            fclose(timeLog_file);
            test3( timeLog_filepath, num_of_clients, 1);
        }
        
        printf("===================Starting KSM1=====================\n");
        resultsLogRAW_file = fopen( resultsLogRAW_filepath, "a" );
        fprintf(resultsLogRAW_file,
              "===================Starting KSM1=====================\n");
        if(resultsLogRAW_file) fclose(resultsLogRAW_file);
        run_test3(&rs, num_of_clients, 1);
        log_data( test3_dat_ksm1_filepath, group_size, &rs );


        set_default_running_stats( &rs );
        printf("===================Pre-test Runs=====================\n");
        for( j = 0; j < ignore_count; j++ ) { // ignore first few iterations
            timeLog_file = fopen( timeLog_filepath, "w" );
            fclose(timeLog_file);
            test3( timeLog_filepath, num_of_clients, 2);
        }
        
        printf("===================Starting KSM2=====================\n");
        resultsLogRAW_file = fopen( resultsLogRAW_filepath, "a" );
        fprintf(resultsLogRAW_file,
                "===================Starting KSM2=====================\n");
        if(resultsLogRAW_file) fclose(resultsLogRAW_file);
    
        run_test3(&rs, num_of_clients, 2);
        log_data( test3_dat_ksm2_filepath, group_size, &rs );

    }

    
    delete_service("group",group_count);

    merge_data(test3_dat_filepath, test3_dat_ksm1_filepath,
                                   test3_dat_ksm2_filepath);
    remove(test3_dat_ksm1_filepath);
    remove(test3_dat_ksm2_filepath);
    remove(timeLog_filepath);

    return 0;
}
Exemple #19
0
int
do_create(int argc, char *argv[])
{
	char c;
	char *buf, *ptr, *instance_name;
	char *inaddr_any_name = NULL;
	int i, status, len, pcnt;
	const char *token_label = NULL;
	const char *filename = NULL;
	const char *certname = NULL;
	const char *username = NULL;
	const char *proxy_port = NULL;
	char *format = NULL;
	boolean_t quote_next;
	char address_port[MAX_ADRPORT_LEN + 1];

	argc -= 1;
	argv += 1;

	/*
	 * Many of these arguments are passed on to kssladm command
	 * in the start method of the SMF instance created. So, we do only
	 * the basic usage checks here and let kssladm check the validity
	 * of the arguments. This is the reason we ignore optarg
	 * for some of the cases below.
	 */
	while ((c = getopt(argc, argv, "vT:d:f:h:i:p:c:C:t:u:x:z:")) != -1) {
		switch (c) {
		case 'd':
			break;
		case 'c':
			break;
		case 'C':
			certname = optarg;
			break;
		case 'f':
			format = optarg;
			break;
		case 'h':
			break;
		case 'i':
			filename = optarg;
			break;
		case 'T':
			token_label = optarg;
			break;
		case 'p':
			break;
		case 't':
			break;
		case 'u':
			username = optarg;
			break;
		case 'x':
			proxy_port = optarg;
			break;
		case 'v':
			verbose = B_TRUE;
			break;
		case 'z':
			break;
		default:
			goto err;
		}
	}

	if (format == NULL || proxy_port == NULL) {
		goto err;
	}

	if (get_portnum(proxy_port, NULL) == 0) {
		(void) fprintf(stderr,
		    gettext("Error: Invalid proxy port value %s\n"),
		    proxy_port);
		goto err;
	}

	if (strcmp(format, "pkcs11") == 0) {
		if (token_label == NULL || certname == NULL) {
			goto err;
		}
	} else if (strcmp(format, "pkcs12") == 0 ||
	    strcmp(format, "pem") == 0) {
		if (filename == NULL) {
			goto err;
		}
	} else {
		goto err;
	}

	pcnt = argc - optind;
	if (pcnt == 1) {
		if (strlen(argv[optind]) < MAX_ADRPORT_LEN) {
			(void) strcpy(address_port, argv[optind]);
		} else {
			(void) fprintf(stderr, gettext(
			    "argument too long -- %s\n"),
			    argv[optind]);
			return (FAILURE);
		}
	} else if (pcnt == 2) {
		if ((len = strlen(argv[optind])) +
		    (strlen(argv[optind + 1])) < MAX_ADRPORT_LEN) {
			(void) strcpy(address_port, argv[optind]);
			address_port[len] = ' ';
			(void) strcpy(address_port + len + 1, argv[optind + 1]);
		} else {
			(void) fprintf(stderr, gettext(
			    "arguments too long -- %s %s\n"),
			    argv[optind], argv[optind + 1]);
			return (FAILURE);
		}
	} else {
		goto err;
	}

	/*
	 * We need to create the kssladm command line in
	 * the SMF instance from the current arguments.
	 *
	 * Construct a buffer with all the arguments except
	 * the -u argument. We have to quote the string arguments,
	 * -T and -C, as they can contain white space.
	 */
	len = 0;
	for (i = 1; i < optind; i++) {
		len += strlen(argv[i]) + 3;
	}

	if ((buf = malloc(len)) == NULL) {
		return (FAILURE);
	}

	ptr = buf;
	quote_next = B_FALSE;
	for (i = 1; i < optind; i++) {
		int arglen =  strlen(argv[i]) + 1;

		if (strncmp(argv[i], "-u", 2) == 0) {
			i++;
			continue;
		}

		if (quote_next) {
			(void) snprintf(ptr, len, "\"%s\" ", argv[i]);
			quote_next = B_FALSE;
			arglen += 2;
		} else {
			(void) snprintf(ptr, len, "%s ", argv[i]);
		}

		quote_next = (strncmp(argv[i], "-T", 2) == 0 ||
		    strncmp(argv[i], "-C", 2) == 0);

		ptr += arglen;
		len -= arglen;
	}
	KSSL_DEBUG("buf=%s\n", buf);

	instance_name = create_instance_name(address_port,
	    &inaddr_any_name, B_TRUE);
	if (instance_name == NULL || inaddr_any_name == NULL) {
		free(buf);
		return (FAILURE);
	}
	KSSL_DEBUG("instance_name=%s\n", instance_name);
	KSSL_DEBUG("inaddr_any_name=%s\n", inaddr_any_name);

	if (username == NULL)
		username = "******";
	status = create_service(instance_name, address_port,
	    buf, username, inaddr_any_name);
	if (status == INSTANCE_OTHER_EXISTS || status == INSTANCE_ANY_EXISTS) {
		if (status == INSTANCE_ANY_EXISTS &&
		    (strcmp(instance_name, inaddr_any_name) != SUCCESS)) {
			/*
			 * The following could result in a misconfiguration.
			 * Better bail out with an error.
			 */
			(void) fprintf(stderr,
			    gettext("Error: INADDR_ANY instance exists."
			    " Can not create a new instance %s.\n"),
			    instance_name);
			free(instance_name);
			free(inaddr_any_name);
			free(buf);
			return (status);
		}

		/*
		 * Delete the existing instance and create a new instance
		 * with the supplied arguments.
		 */
		KSSL_DEBUG("Deleting duplicate instance\n");
		if (delete_instance(instance_name) != SUCCESS) {
			(void) fprintf(stderr,
			    gettext(
			    "Error: Can not delete existing instance %s.\n"),
			    instance_name);
		} else {
			(void) fprintf(stdout, gettext(
			    "Note: reconfiguring the existing instance %s.\n"),
			    instance_name);
			status = create_service(instance_name, address_port,
			    buf, username, inaddr_any_name);
		}
	}

	free(instance_name);
	free(inaddr_any_name);
	free(buf);
	return (status);

err:
	usage_create(B_TRUE);
	return (ERROR_USAGE);
}