Пример #1
0
/* register */
int32_t Directory_register(String const * title, Buffer * csr, Buffer * x509)
{
	static const char cacert_csr[] = "/cacert.csr";
	static const char begin[] = "-----BEGIN CERTIFICATE REQUEST-----\n";
	int ret;
	struct stat st;
	size_t len;
	char * filename;

	/* validate title */
	if(*title == '\0' || *title == '.' || strchr(title, '/') != NULL)
		return 1;
	/* validate request */
	if((len = buffer_get_size(csr)) < sizeof(begin))
		return error_set_print(PACKAGE, 1, "%s", "Request too short");
	if(memcmp(buffer_get_data(csr), begin, sizeof(begin) - 1) != 0)
		return error_set_print(PACKAGE, 1, "%s", "Incorrect request");
	/* verify the title is unique */
	if(lstat(title, &st) != -1 || errno != ENOENT)
		return error_set_print(PACKAGE, 1, "%s%s%s", title, ": ",
				strerror(EEXIST));
	/* request certificate */
	if(mkdir(title, 0777) != 0)
		return error_set_print(PACKAGE, 1, "%s%s%s", title, ": ",
				strerror(errno));
	if((filename = malloc(strlen(title) + sizeof(cacert_csr))) == NULL)
		return error_set_print(PACKAGE, 1, "%s", strerror(errno));
	sprintf(filename, "%s%s", title, cacert_csr);
	ret = _x509_from_request(filename, csr, x509);
	free(filename);
	return ret;
}
Пример #2
0
static int _appbroker(char const * outfile, char const * filename)
{
	AppBroker appbroker;

	if((appbroker.config = config_new()) == NULL)
		return error_print(APPBROKER_PROGNAME);
	if(config_load(appbroker.config, filename) != 0)
	{
		config_delete(appbroker.config);
		return error_print(APPBROKER_PROGNAME);
	}
	appbroker.prefix = config_get(appbroker.config, NULL, "service");
	if((appbroker.outfile = outfile) == NULL)
		appbroker.fp = stdout;
	else if((appbroker.fp = fopen(outfile, "w")) == NULL)
	{
		config_delete(appbroker.config);
		return error_set_print(APPBROKER_PROGNAME, 1, "%s: %s", outfile,
				strerror(errno));
	}
	_appbroker_head(&appbroker);
	_appbroker_constants(&appbroker);
	_appbroker_calls(&appbroker);
	_appbroker_tail(&appbroker);
	if(outfile != NULL)
		fclose(appbroker.fp);
	config_delete(appbroker.config);
	return 0;
}
Пример #3
0
static int _main_add_option(C99Prefs * prefs, char const * option)
{
	C99Option * p;
	char * q;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, option);
#endif
	if(strlen(option) == 0)
		return 1;
	if((p = realloc(prefs->options, sizeof(*p)
					* (prefs->options_cnt + 1))) == NULL)
		return error_set_print(PACKAGE, 1, "%s", strerror(errno));
	prefs->options = p;
	p = &prefs->options[prefs->options_cnt];
	if((p->name = string_new(option)) == NULL)
		return 1;
	p->value = NULL;
	if((q = strstr(p->name, "=")) != NULL)
	{
		*q = '\0';
		p->value = q + 1;
	}
	prefs->options_cnt++;
	return 0;
}
Пример #4
0
static int _cpp(Prefs * prefs, int filec, char * filev[])
{
	int ret = 0;
	FILE * fp;
	int i;

	if(prefs->outfile == NULL)
		fp = stdout;
	else if((fp = fopen(prefs->outfile, "w")) == NULL)
		return error_set_print("cpp", 1, "%s: %s", prefs->outfile,
				strerror(errno));
	for(i = 0; i < filec; i++)
		ret |= _cpp_do(prefs, fp, filev[i]);
	if(fclose(fp) != 0)
		return error_set_print("cpp", 1, "%s: %s", prefs->outfile,
				strerror(errno));
	return ret;
}
Пример #5
0
static int _main_add_path(Prefs * prefs, char const * path)
{
	const char ** p;

	if((p = realloc(prefs->paths, sizeof(*p) * (prefs->paths_cnt + 1)))
			== NULL)
		return error_set_print(PACKAGE, 1, "%s", strerror(errno));
	prefs->paths = p;
	prefs->paths[prefs->paths_cnt++] = path;
	return 0;
}
Пример #6
0
/* modem_helper_error */
static int _modem_helper_error(Modem * modem, char const * message, int ret)
{
	ModemEvent event;

	if(modem == NULL || modem->callback == NULL)
		return error_set_print(PACKAGE, ret, "%s", message);
	event.type = MODEM_EVENT_TYPE_ERROR;
	event.error.message = message;
	modem->callback(modem->priv, &event);
	return ret;
}
Пример #7
0
/* PRE	title is trusted */
static void _request_child(char const * filename, int fd)
{
	static const char openssl_cnf[] = "/openssl.cnf";
	char const * title;
	char * cnf;

	if((title = config_get(config, "", "authority")) == NULL)
		exit(error_print(PACKAGE));
	if((cnf = malloc(strlen(title) + sizeof(openssl_cnf))) == NULL)
		exit(error_set_print(PACKAGE, 1, "%s", strerror(errno)));
	if(dup2(fd, 1) == -1)
		exit(error_set_print(PACKAGE, 1, "%s%s", "dup2: ", strerror(
						errno)));
	sprintf(cnf, "%s%s", title, openssl_cnf);
	execlp("openssl", "openssl", "ca", "-config", cnf, "-extensions",
			"v3_ca", "-policy", "policy_anything", "-days", "3650",
			"-batch", "-in", filename, NULL);
	exit(error_set_print(PACKAGE, 127, "%s%s", "openssl: ", strerror(
					errno)));
}
Пример #8
0
static int _main_add_undefine(Prefs * prefs, char const * undefine)
{
	const char ** p;

	if(strlen(undefine) == 0)
		return 1;
	if((p = realloc(prefs->undefines, sizeof(*p)
					* (prefs->undefines_cnt + 1))) == NULL)
		return error_set_print(PACKAGE, 1, "%s", strerror(errno));
	prefs->undefines = p;
	prefs->undefines[prefs->undefines_cnt++] = undefine;
	return 0;
}
Пример #9
0
static int _main_add_path(C99Prefs * prefs, char const * path)
{
	const char ** p;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, path);
#endif
	if((p = realloc(prefs->paths, sizeof(*p) * (prefs->paths_cnt + 1)))
			== NULL)
		return error_set_print(PACKAGE, 1, "%s", strerror(errno));
	prefs->paths = p;
	prefs->paths[prefs->paths_cnt++] = path;
	return 0;
}
Пример #10
0
static int _main_add_define(Prefs * prefs, char * define)
{
	const char ** p;
	char * value;

	if(strlen(define) == 0)
		return 1;
	value = strtok(define, "=");
	if((p = realloc(prefs->defines, sizeof(*p) * (prefs->defines_cnt + 1)))
			== NULL)
		return error_set_print(PACKAGE, 1, "%s", strerror(errno));
	prefs->defines = p;
	prefs->defines[prefs->defines_cnt++] = define;
	return 0;
}
Пример #11
0
static int _main_default_defines(C99Prefs * prefs)
	/* FIXME define these in the as plug-in instead */
{
	struct utsname uts;
	static char sysname[sizeof(uts.sysname) + 7];
	static char machine[sizeof(uts.machine) + 7];

	if(uname(&uts) != 0)
		return error_set_print(PACKAGE, 1, "%s", strerror(errno));
	snprintf(sysname, sizeof(sysname), "__%s__=1", uts.sysname);
	snprintf(machine, sizeof(machine), "__%s__=1", uts.machine);
	if(_main_add_define(prefs, sysname) != 0
			|| _main_add_define(prefs, machine) != 0)
		return 1;
	return 0;
}
Пример #12
0
/* client_add_socket */
static VPNClient * _client_add_socket(VPNClient * client, int32_t fd)
{
	int32_t * p;

	if((client = _client_add(client)) == NULL)
		return NULL;
	if((p = realloc(client->sockets, sizeof(*p)
					* (client->sockets_cnt + 1))) == NULL)
	{
		error_set_print(PACKAGE, 1, "%s", strerror(errno));
		return NULL;
	}
	client->sockets = p;
	client->sockets[client->sockets_cnt++] = fd;
	return client;
}
Пример #13
0
static int _main_add_undefine(C99Prefs * prefs, char const * undefine)
{
	const char ** p;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, undefine);
#endif
	if(strlen(undefine) == 0)
		return 1;
	if((p = realloc(prefs->undefines, sizeof(*p)
					* (prefs->undefines_cnt + 1))) == NULL)
		return error_set_print(PACKAGE, 1, "%s", strerror(errno));
	prefs->undefines = p;
	prefs->undefines[prefs->undefines_cnt++] = undefine;
	return 0;
}
Пример #14
0
static int _main_add_define(C99Prefs * prefs, char * define)
{
	char ** p;
	char * value;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, define);
#endif
	if(strlen(define) == 0)
		return _usage();
	value = strtok(define, "=");
	if((p = realloc(prefs->defines, sizeof(*p) * (prefs->defines_cnt + 1)))
			== NULL)
		return error_set_print(PACKAGE, 1, "%s", strerror(errno));
	prefs->defines = p;
	prefs->defines[prefs->defines_cnt++] = define;
	return 0;
}
Пример #15
0
int damon_refresh(DaMon * damon)
{
    unsigned int i;
    AppClient * ac = NULL;
    char * rrd = NULL;
    char * p;
    Host * hosts = damon->hosts;

#ifdef DEBUG
    fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
    for(i = 0; i < damon->hosts_cnt; i++)
    {
        if((ac = hosts[i].appclient) == NULL)
            if((ac = _refresh_connect(&hosts[i], damon->event))
                    == NULL)
                continue;
        if((p = realloc(rrd, string_length(hosts[i].hostname) + 12))
                == NULL) /* XXX avoid this constant */
            break;
        rrd = p;
        if(_refresh_uptime(ac, &hosts[i], rrd) != 0
                || _refresh_load(ac, &hosts[i], rrd) != 0
                || _refresh_ram(ac, &hosts[i], rrd) != 0
                || _refresh_swap(ac, &hosts[i], rrd) != 0
                || _refresh_procs(ac, &hosts[i], rrd) != 0
                || _refresh_users(ac, &hosts[i], rrd) != 0
                || _refresh_ifaces(ac, &hosts[i], rrd) != 0
                || _refresh_vols(ac, &hosts[i], rrd) != 0)
        {
            appclient_delete(ac);
            hosts[i].appclient = NULL;
            continue;
        }
        ac = NULL;
    }
    free(rrd);
    if(ac != NULL)
        error_set_print(PROGNAME, 1, "%s", "refresh: An error occured");
    return 0;
}
Пример #16
0
/* compose_error */
int compose_error(Compose * compose, char const * message, int ret)
{
	GtkWidget * dialog;

	if(compose == NULL)
		return error_set_print("mailer", ret, "%s", message);
	dialog = gtk_message_dialog_new(GTK_WINDOW(compose->window),
			GTK_DIALOG_DESTROY_WITH_PARENT,
			GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
#if GTK_CHECK_VERSION(2, 6, 0)
			"%s", _("Error"));
	gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
#endif
			"%s", message);
	gtk_window_set_title(GTK_WINDOW(dialog), _("Error"));
	gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(
				compose->window));
	g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(
				gtk_widget_destroy), NULL);
	gtk_widget_show(dialog);
	return ret;
}
Пример #17
0
/* client_add */
static VPNClient * _client_add(VPNClient * client)
{
	void * id;
	VPNClient * p;

	if(client == NULL && (client = _client_get()) != NULL)
		return client;
	if((id = appserver_get_client_id(_appserver)) == NULL)
	{
		error_print(PACKAGE);
		return NULL;
	}
	if((p = realloc(_clients, sizeof(*p) * (_clients_cnt + 1))) == NULL)
	{
		error_set_print(PACKAGE, 1, "%s", strerror(errno));
		return NULL;
	}
	_clients = p;
	p = &_clients[_clients_cnt++];
	p->id = id;
	p->sockets = NULL;
	p->sockets_cnt = 0;
	return p;
}
Пример #18
0
/* client_remove_socket */
static VPNClient * _client_remove_socket(VPNClient * client, int32_t fd)
{
	size_t i;
	int32_t * p;

	if(fd < 0) /* XXX should never happen */
	{
		error_set_print(PACKAGE, 1, "%s", strerror(EINVAL));
		return NULL;
	}
	if(client == NULL && (client = _client_get()) == NULL)
		return NULL;
	for(i = 0; i < client->sockets_cnt; i++)
		if(client->sockets[i] == fd)
			break;
	if(i == client->sockets_cnt)
		return client;
	p = &client->sockets[i];
	memmove(p, p + 1, (--client->sockets_cnt - i) * sizeof(*p));
	if((p = realloc(client->sockets, sizeof(*p) * client->sockets_cnt))
			!= NULL || client->sockets_cnt == 0)
		client->sockets = p; /* we can ignore errors */
	return client;
}
Пример #19
0
/* probe_perror */
static int _probe_perror(char const * message, int ret)
{
	error_set_print(PROGNAME, ret, "%s%s%s", message ? message : "",
			message ? ": " : "", strerror(errno));
	return ret;
}