+/*
+ * check_tracing_group
+ *
+ * Check if the specified group name exist.
+ * If yes, 0, else -1
+ */
+static int check_tracing_group(const char *grp_name)
+{
+ struct group *grp_tracing; /* no free(). See getgrnam(3) */
+ gid_t *grp_list;
+ int grp_list_size, grp_id, i;
+ int ret = -1;
+
+ /* Get GID of group 'tracing' */
+ grp_tracing = getgrnam(grp_name);
+ if (grp_tracing == NULL) {
+ /* NULL means not found also. getgrnam(3) */
+ if (errno != 0) {
+ perror("getgrnam");
+ }
+ goto end;
+ }
+
+ /* Get number of supplementary group IDs */
+ grp_list_size = getgroups(0, NULL);
+ if (grp_list_size < 0) {
+ perror("getgroups");
+ goto end;
+ }
+
+ /* Alloc group list of the right size */
+ grp_list = malloc(grp_list_size * sizeof(gid_t));
+ grp_id = getgroups(grp_list_size, grp_list);
+ if (grp_id < -1) {
+ perror("getgroups");
+ goto free_list;
+ }
+
+ for (i = 0; i < grp_list_size; i++) {
+ if (grp_list[i] == grp_tracing->gr_gid) {
+ ret = 0;
+ break;
+ }
+ }
+
+free_list:
+ free(grp_list);
+
+end:
+ return ret;
+}
+
+/*
+ * set_session_daemon_path
+ *
+ * Set sessiond socket path by putting it in
+ * the global sessiond_sock_path variable.
+ */
+static int set_session_daemon_path(void)
+{
+ int ret;
+
+ /* Are we in the tracing group ? */
+ ret = check_tracing_group(tracing_group);
+ if (ret < 0 && getuid() != 0) {
+ if (sprintf(sessiond_sock_path, DEFAULT_HOME_CLIENT_UNIX_SOCK,
+ getenv("HOME")) < 0) {
+ return -ENOMEM;
+ }
+ } else {
+ strncpy(sessiond_sock_path, DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
+ sizeof(DEFAULT_GLOBAL_CLIENT_UNIX_SOCK));
+ }
+
+ return 0;
+}
+