Question

1. Assume the following struct is declared for the permission list of a file in Linux....

1. Assume the following struct is declared for the permission list of a file in Linux.
Each permission (u or g or o) is represented as an octal. For example, u=7 means rwx, u=5 means r-x.

Note: "unsigned char" means a byte, not a character or a letter or a string.

typedef struct {
unsigned int uid; // owner id
unsigned int gid; // group id
unsigned char u; // owner's permission
unsigned char g; // group's permission
unsigned char o; // other's permission
} Permission;

The permission check procedure is
(1) A user requests an operation p on a file f.
(2) If the user is the owner of the file, the operation will be checked against the owner's permission of the file. The result is either grant or deny.
(3) Otherwise, if the user is not the owner but in the group of the file, the operation will be checked against the group's permission of the file. The result is either grant or deny.
(4) Otherwise, if the user is neither the owner nor in the group of the file, the operation will be checked against the other's permission of the file. The result is either grant or deny.

Write a C/C++ function "int accesscheck(unsigned int uid, unsigned int gid, unsigned int p, int f)" to enforce access control in Linux.
The arguments of the function accesscheck are explained below:
1) uid and gid are the user id and the group id of the user who requests to take an operation on the file.
2) f is the file id.
3) p is the requested operation. For example, p=7 means three operations rwx, p=6 means two operations rw-, p=1 means one operation --x.
The function return 1 if access is permitted, otherwise 0.

Request will be granted only if p is contained by the permission set of the file.
Assume "Permission getPermission(int f)" can get the permission of the file f.

For example, f's permission is rwxr-xr-x 1000(uid) 2000(gid). Then, accesscheck(1000, 1000, 6, f) returns 1, but accesscheck(2000, 2000, 6, f) returns 0.

Copy and paste your code in report and explain each line of code of your function in comments.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

#include <stdio.h>

typedef struct {
unsigned int uid; // owner id
unsigned int gid; // group id
unsigned char u; // owner's permission
unsigned char g; // group's permission
unsigned char o; // other's permission
}Permission;

int accesscheck(unsigned int uid, unsigned int gid, unsigned int p, int f)
{
    Permission cPerm = getPermission(f);//copies permissions of current file to a structer
    if(cPerm.uid == uid)//checking for user id of passed and current(opened with file id)
    {
        if(cPerm.p >= p)//checking for current process is valid for the current id (group or user)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    else if(cPerm.gid == gid)//checking for group id of passed and current(opened with file id)
    {
        if(cPerm.p >= p)//checking for current process is valid for the current id (group or user)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    else if(cPerm.o == gid)//checking for passed id and current's others id(opened with file id)
    {
        if(cPerm.p >= p)//checking for current process is valid for the current id (group or user)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
  
}
int main()
{

    return 0;
}

Thanks and kindly upvote.

Add a comment
Know the answer?
Add Answer to:
1. Assume the following struct is declared for the permission list of a file in Linux....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • UNIX File Permission help, please answer the questions in the green boxes. Thank you Lab 03...

    UNIX File Permission help, please answer the questions in the green boxes. Thank you Lab 03 File Permissions In this lab we will: learn about file permissions learn to create symbolic links and hard links Utilities that will be utilized in this Lab: us, cd, less, cat touch, chmod id umask, mkdir, In, echo and redirection Users and Groups Linux supports several methods of controlling access to files an directories. In this lab we are going to learn the traditional...

  • photos for each question are all in a row (1 point) In the following questions, use...

    photos for each question are all in a row (1 point) In the following questions, use the normal distribution to find a confidence interval for a difference in proportions pu - P2 given the relevant sample results. Give the best point estimate for p. - P2, the margin of error, and the confidence interval. Assume the results come from random samples. Give your answers to 4 decimal places. 300. Use 1. A 80% interval for pı - P2 given that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT