ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Arseny Maslennikov <ar@cs.msu.ru>
To: Alex Gladkov <legion@altlinux.ru>, devel@lists.altlinux.org
Cc: ldv@altlinux.org
Subject: Re: [devel] [PATCH hasher-priv v1 1/3] config.c
Date: Thu, 17 Sep 2020 16:11:56 +0300
Message-ID: <20200917131156.GH286846@cello> (raw)
In-Reply-To: <9bca7626b593f896de4283cba2d6290ec99eb4f2.1576183643.git.legion@altlinux.org>

[-- Attachment #1: Type: text/plain, Size: 5656 bytes --]

On Fri, Dec 13, 2019 at 12:42:03PM +0100, Alex Gladkov wrote:
> diff --git a/hasher-priv/config.c b/hasher-priv/config.c
> index e3fedcd..6b6bdb1 100644
> --- a/hasher-priv/config.c
> +++ b/hasher-priv/config.c
> @@ -1,6 +1,7 @@
>
>  /*
>    Copyright (C) 2003-2019  Dmitry V. Levin <ldv@altlinux.org>
> +  Copyright (C) 2019  Alexey Gladkov <legion@altlinux.org>
>
>    Configuration support module for the hasher-priv program.
>
> @@ -19,13 +20,17 @@
>  #include <unistd.h>
>  #include <limits.h>
>  #include <pwd.h>
> +#include <grp.h>
>
>  #include "priv.h"
>  #include "xmalloc.h"
> +#include "logging.h"
>
>  const char *const *chroot_prefix_list;
>  const char *chroot_prefix_path;
>  const char *change_user1, *change_user2;
> +char *server_control_group = NULL;
> +char *server_pidfile = NULL;
>  const char *term;
>  const char *x11_display, *x11_key;
>  str_list_t allowed_devices;
> @@ -33,6 +38,8 @@ str_list_t allowed_mountpoints;
>  str_list_t requested_mountpoints;
>  uid_t   change_uid1, change_uid2;
>  gid_t   change_gid1, change_gid2;
> +gid_t   server_gid;
> +unsigned long server_session_timeout = 0;
>  mode_t  change_umask = 022;
>  int change_nice = 8;
>  int     makedev_console;
> @@ -42,6 +49,7 @@ int share_caller_network = 0;
>  int share_ipc = -1;
>  int share_network = -1;
>  int share_uts = -1;
> +int server_log_priority = -1;
>  change_rlimit_t change_rlimit[] = {
>
>  /* Per-process CPU limit, in seconds.  */
> @@ -209,7 +217,7 @@ parse_rlim(const char *name, const char *value, const char *optname,
>  }
>
>  static unsigned long
> -str2wlim(const char *name, const char *value, const char *filename)
> +str2ul(const char *name, const char *value, const char *filename)
>  {
>  	char   *p = 0;
>  	unsigned long long n;
> @@ -229,7 +237,7 @@ static void
>  modify_wlim(unsigned long *pval, const char *value,
>  	    const char *optname, const char *filename, int is_system)
>  {
> -	unsigned long val = str2wlim(optname, value, filename);
> +	unsigned long val = str2ul(optname, value, filename);
>
>  	if (is_system || *pval == 0 || (val > 0 && val < *pval))
>  		*pval = val;
> @@ -633,3 +641,134 @@ parse_env(void)
>  	if ((e = getenv("requested_mountpoints")))
>  		parse_str_list(e, &requested_mountpoints);
>  }
> +
> +static void
> +check_server_control_group(void)

Bad (IOW, unlucky) naming; especially since in a later patch
hasher-privd deals with cgroups.

Is this related to the socket inode's gid in /run?

> +{
> +	struct group *gr;
> +
> +	if (!server_control_group || !*server_control_group)
> +		error(EXIT_FAILURE, 0, "config: undefined: control_group");
> +
> +	gr = getgrnam(server_control_group);
> +
> +	if (!gr || !gr->gr_name)
> +		error(EXIT_FAILURE, 0, "config: control_group: %s lookup failure", server_control_group);
> +
> +	server_gid = gr->gr_gid;
> +}
> +
> +static void
> +set_server_config(const char *name, const char *value, const char *filename)
> +{
> +	if (!strcasecmp("priority", name)) {
> +		server_log_priority = logging_level(value);
> +	} else if (!strcasecmp("session_timeout", name)) {
> +		server_session_timeout = str2ul(name, value, filename);
> +	} else if (!strcasecmp("pidfile", name)) {
> +		free(server_pidfile);
> +		server_pidfile = xstrdup(value);
> +	} else if (!strcasecmp("control_group", name)) {
> +		free(server_control_group);
> +		server_control_group = xstrdup(value);
> +	} else {
> +		bad_option_name(name, filename);
> +	}
> +}
> +
> +static void
> +read_server_config(int fd, const char *name)
> +{
> +	FILE *fp = fdopen(fd, "r");
> +	char buf[BUFSIZ];
> +	unsigned line;
> +
> +	if (!fp)
> +		error(EXIT_FAILURE, errno, "fdopen: %s", name);
> +
> +	for (line = 1; fgets(buf, BUFSIZ, fp); ++line) {
> +		const char *start, *left;
> +		char   *eq, *right, *end;
> +
> +		for (start = buf; *start && isspace(*start); ++start)
> +			;
> +
> +		if (!*start || '#' == *start)
> +			continue;
> +
> +		if (!(eq = strchr(start, '=')))
> +			error(EXIT_FAILURE, 0, "%s: syntax error at line %u",
> +			      name, line);
> +
> +		left = start;
> +		right = eq + 1;
> +
> +		for (; eq > left; --eq)
> +			if (!isspace(eq[-1]))
> +				break;
> +
> +		if (left == eq)
> +			error(EXIT_FAILURE, 0, "%s: syntax error at line %u",
> +			      name, line);
> +
> +		*eq = '\0';
> +		end = right + strlen(right);
> +
> +		for (; right < end; ++right)
> +			if (!isspace(*right))
> +				break;
> +
> +		for (; end > right; --end)
> +			if (!isspace(end[-1]))
> +				break;
> +
> +		*end = '\0';
> +		set_server_config(left, right, name);
> +	}
> +
> +	if (ferror(fp))
> +		error(EXIT_FAILURE, errno, "fgets: %s", name);
> +
> +	if (fclose(fp))
> +		error(EXIT_FAILURE, errno, "fclose: %s", name);
> +}
> +
> +static void
> +load_server_config(const char *name)
> +{
> +	struct stat st;
> +	int fd = open(name, O_RDONLY | O_NOFOLLOW | O_NOCTTY);
> +
> +	if (fd < 0)
> +		error(EXIT_FAILURE, errno, "open: %s", name);
> +
> +	if (fstat(fd, &st) < 0)
> +		error(EXIT_FAILURE, errno, "fstat: %s", name);
> +
> +	stat_root_ok_validator(&st, name);
> +
> +	if (!S_ISREG(st.st_mode))
> +		error(EXIT_FAILURE, 0, "%s: not a regular file", name);
> +
> +	if (st.st_size > MAX_CONFIG_SIZE)
> +		error(EXIT_FAILURE, 0, "%s: file too large: %lu",
> +		      name, (unsigned long) st.st_size);
> +
> +	read_server_config(fd, name);
> +}
> +
> +void
> +configure_server(void)
> +{
> +	safe_chdir("/", stat_root_ok_validator);
> +	safe_chdir("etc/hasher-priv", stat_root_ok_validator);
> +	load_server_config("server");
> +	check_server_control_group();
> +}
> +
> +void
> +free_server_configuration(void)
> +{
> +	free(server_pidfile);
> +	free(server_control_group);
> +}

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2020-09-17 13:11 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-13 11:42 [devel] [PATCH hasher-priv v1 0/3] Make a daemon from the hasher-priv Alex Gladkov
2019-12-13 11:42 ` [devel] [PATCH hasher-priv v1 1/3] " Alex Gladkov
2020-09-17 13:10   ` Arseny Maslennikov
2020-10-01 19:43     ` Alexey Gladkov
2020-10-01 21:24       ` Arseny Maslennikov
2020-10-01 23:38         ` Alexey Gladkov
2020-09-17 13:10   ` [devel] [PATCH hasher-priv v1 1/3] *literacy* Arseny Maslennikov
2020-09-17 13:11   ` [devel] [PATCH hasher-priv v1 1/3] caller.c Arseny Maslennikov
2020-09-17 13:55     ` Arseny Maslennikov
2020-09-17 13:11   ` [devel] [PATCH hasher-priv v1 1/3] caller_server.c, caller_task.c Arseny Maslennikov
2020-10-01 19:47     ` Alexey Gladkov
2020-09-17 13:11   ` Arseny Maslennikov [this message]
2020-09-18 10:42     ` [devel] [PATCH hasher-priv v1 1/3] config.c Dmitry V. Levin
2020-09-17 13:12   ` [devel] [PATCH hasher-priv v1 1/3] hasher-privd.c Arseny Maslennikov
2020-09-17 13:12   ` [devel] [PATCH hasher-priv v1 1/3] logging.c Arseny Maslennikov
2020-09-17 13:12   ` [devel] [PATCH hasher-priv v1 1/3] Makefile Arseny Maslennikov
2020-09-17 15:09     ` Vladimir D. Seleznev
2020-09-18 10:48     ` Dmitry V. Levin
2020-09-18 10:54       ` Andrey Savchenko
2020-09-18 11:33     ` Dmitry V. Levin
2020-09-18 12:24       ` Arseny Maslennikov
2020-09-17 13:12   ` [devel] [PATCH hasher-priv v1 1/3] server.conf Arseny Maslennikov
2020-09-18 10:50     ` Dmitry V. Levin
2020-09-18 10:57       ` Arseny Maslennikov
2019-12-13 11:42 ` [devel] [PATCH hasher-priv v1 2/3] Add systemd and sysvinit service files Alex Gladkov
2020-06-17 22:31   ` Mikhail Novosyolov
2020-06-17 22:38     ` Mikhail Novosyolov
2020-06-17 22:50       ` Alexey Gladkov
2020-06-17 22:43     ` Alexey Gladkov
2020-06-17 22:53       ` Mikhail Novosyolov
2020-09-17 13:10   ` Arseny Maslennikov
2020-10-01 17:25     ` Alexey Gladkov
2020-10-01 17:50       ` Arseny Maslennikov
2019-12-13 11:42 ` [devel] [PATCH hasher-priv v1 3/3] Add cgroup support Alex Gladkov
2020-09-17 13:11   ` Arseny Maslennikov
2020-10-01 19:17     ` Alexey Gladkov
2020-10-01 20:23       ` Arseny Maslennikov
2020-10-02  0:42         ` Alexey Gladkov
2020-10-02 11:46           ` Arseny Maslennikov
2020-10-02 12:58             ` Alexey Gladkov
2019-12-15  8:50 ` [devel] [PATCH hasher-priv v1 0/3] Make a daemon from the hasher-priv Alexey Tourbin
2019-12-15 23:33   ` Andrey Savchenko
2019-12-16  9:35   ` Dmitry V. Levin
2019-12-29 11:03     ` Alexey Tourbin
2020-03-16 10:34 ` Alexey Gladkov
2020-06-17 22:01 ` Alexey Gladkov
2020-09-17 13:09 ` Arseny Maslennikov
2020-10-01 17:21   ` Alexey Gladkov
2020-10-01 17:44     ` Arseny Maslennikov
2020-10-01 20:01       ` Alexey Gladkov
2020-10-01 21:53         ` Arseny Maslennikov
2020-10-01 23:55           ` Alexey Gladkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200917131156.GH286846@cello \
    --to=ar@cs.msu.ru \
    --cc=devel@lists.altlinux.org \
    --cc=ldv@altlinux.org \
    --cc=legion@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git