Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:01:01+00:00 2026-06-12T08:01:01+00:00

Lets add a new group and user and add it into system group video

  • 0

Lets add a new group and user and add it into system group video

$ sudo addgroup --system mydaemon
$ sudo adduser --system --no-create-home --ingroup mydaemon mydaemon
$ sudo adduser mydaemon video

Create a file and change its owner to root and group to video

$ touch video0
$ sudo chown root:video video0
$ sudo chmod 0660 video0

Now consider a simple application written in C using setgid() and setuid()

/* perms.c */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>


int main(int argc, char const *argv[])
{
    int ret;
    int gid;
    int uid;
    struct passwd *pw;
    struct group  *gr;

    pw = getpwnam("mydaemon");
    if (pw) {
        ret = setgid(pw->pw_gid);
        if (ret < 0) {
            printf("error with setgid\n");
            exit(1);
        }

        ret = setuid(pw->pw_uid);       
        if (ret < 0) {
            printf("error with setuid\n");
            exit(1);
        }
    }

    pw = getpwuid(getuid());
    gr = getgrgid(getgid());

    printf("gid: %d gr_name: %s\n", gr->gr_gid, gr->gr_name);
    printf("uid: %d user_name: %s\n", pw->pw_uid, pw->pw_name);

    ret = open("video0", O_RDWR);

    printf("open status: %d (errno %d)\n", ret, errno);

    return 0;
}

After compilation we can run it as normal user:

$ ./perms
error with setgid

It fails because we do not have permissions to setgid
So run it directly as mydaemon:

$ sudo -u mydaemon ./perms
gid: 126 gr_name: mydaemon
uid: 116 user_name: mydaemon
open status: 3 (errno 0)

Fine, I can do setgid and setuid (I’m the same user) and I can open the file as expected

Now run it as root:

$ sudo ./perms
gid: 126 gr_name: mydaemon
uid: 116 user_name: mydaemon
open status: -1 (errno 13)

I can do setgid and setuid, getgid and getuid says that I’m running as mydaemon but I cant open the file. (errno 13 is EACCES: Permission denied)

Where is the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:01:02+00:00Added an answer on June 12, 2026 at 8:01 am

    You should use initgroups() call to initialize groups according to group database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my iPhone project I want to add a new resource folder. Lets say
Let's say I have a DataTable: DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn(Country, typeof(string)));
Let's say we have a service to add a new hotel: > POST /hotel
Let's say I've got: Dim los1 as New List(Of String) los1.Add(Some value) Dim los2
I have a form which lets you add names to the table and shows
Lets say i wanted to add another variable to the database can anybody tell
Lets say I wan't to add 1 to an integer. This will only be
I would like to add details to the incoming call screen on android. lets
string str = one three; string::iterator it; string add = two ; Lets say
I have a simple user signup form with a checkbox that lets users get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.