Question

In: Computer Science

int main() { system("ls"); return 0; } Please compile the above program, and change its owner...

int main()

{

system("ls");

return 0;

}

Please compile the above program, and change its owner to root, and make it a Set-UID program. Can you let this Set-UID program run your code instead of /bin/ls? If you can, is your code running with the root privilege? Describe and explain your observations.

Solutions

Expert Solution

To change the file permission use chmod command to give the permission to the file.

in the command prompt enter the chmod u+s "File_Name.c". It will set the UID of the file

The code is not running with root privilege. But the file is running with the root privilege.

//include the header file

#include<stdio.h>

#include <stdlib.h>

int main()

{

    system("ls"); //it will execute the command

    return 0;

}

USER$ ls -l systemLSS.c
---------- 1 USER staff 134 Sep 15 19:08 systemLSS.c
USER$ chmod u+s systemLSS.c
USER$ ls -l systemLSS.c
---S------ 1 USER staff 134 Sep 15 19:08 systemLSS.c
USER$ gcc systemLSS.c -o systemLSS
error: error reading 'systemLSS.c'
1 error generated.

Enter the command with sudo to run the program and enter the root password
USER$ sudo gcc systemLSS.c -o systemLSS
Password:

Run the program to list the file in the directory which the user has the file
USER$ ./systemLSS
Animal                   filreadwrite.c
AnimalBirdChoose.cpp           filreadwrite.layout
ArraySum.cpp               filreadwrite.o


Related Solutions

Assume that the following Ada like program compile successfully. int k = 0; A[3] = {0,...
Assume that the following Ada like program compile successfully. int k = 0; A[3] = {0, 1, 2}; void f(int p) {      cout<< A[k];      p*=3;      cout<< A[k];      p*=3;      cout<< A[k]; } int main () {      f(A[k++]);        // postfix      cout << A[1] << A[2] << endl; {    What is printed on the screen assuming? Pass by value Pass by reference Pass by value-result (assume lvalue is computed at call time) Pass by value-result...
Please comment, exactly how this program works? #include <stdio.h> int main() { int i,j; int a[1000];...
Please comment, exactly how this program works? #include <stdio.h> int main() { int i,j; int a[1000]; for(i=0;i<1000;i++) a[i]=1;    for(i=2;i<1000;i++) { if(a[i]==1){ for(j=i+1;j<1000;j++) {if(j%(i)==0) a[j]=0; } } } printf("print numbers are:\n"); for(i=2;i<=1000;i++) if(a[i]==1) printf("%d, ",i); }
static int product(int x,int y){ if(x==0||y==0){//checking if x or y is 0 return 0;//if x or...
static int product(int x,int y){ if(x==0||y==0){//checking if x or y is 0 return 0;//if x or y is 0, then the return value and x*y will be zero. }else if(y<0&&x<0){ x=-x;//Changing the sign of x y=-y;//Changing the sign of y }else if(x>=1){ return (y+product(x-1,y)); } return (x+product(x,y-1)); } find the space complexity and the time complexity of the above algorithm.
c program //the file's size in bytes unsigned int fileSize(const char* name){     return 0; }...
c program //the file's size in bytes unsigned int fileSize(const char* name){     return 0; } //same as fileSize except if the file is a directory then it recursively finds the size of directory and all files it contains unsigned int fileSizeRec(const char* name){     return 0; }
(True or False) The following function will compile. void print(int num) { return num+1; } Group...
(True or False) The following function will compile. void print(int num) { return num+1; } Group of answer choices True False Flag this Question Question 2 10 pts (True or False) The following code will output "I was true". bool isGreater(string s1, string s2) { if(s1 > s2) { return true; } return false; } int main() { if(isGreater("before","back")) { cout << "I was true"; } else { cout << "I was false"; } return 0; } Group of answer...
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;...
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;       char B=10; cout<<”Enter Value of A”; cin<<A; show(A) show(50)          }       cin.get(); } int show(int x); { cout<<”Value is =” <<X cout<<endl; }
#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10;...
#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10; i++){ cout << " Enter " << i << " number: "; cin >> num; if ( num%2==0){ even++; sum+=num; } else { odd++; sum2+=num; if(num>largest){ largest = num; } if(num<largest) { smallest = num; } } cout << " The sum of even number is : " << sum << endl; cout << " The total-count of even number is : " <<...
#include <stdio.h> int main(void) { float funds = 1.0, cost = 0.1; int candies = 0;...
#include <stdio.h> int main(void) { float funds = 1.0, cost = 0.1; int candies = 0; while(cost <= funds) { candies += 1; funds -= cost; cost += 0.1; } printf("%d candies with $%.2f left over.\n",candies,funds); return 0; } When you compile and run this code you get 3 candies with $0.40 left over. Without knowing how floating point numbers work in a computer, would this result be expected? Explain why or why not. Explain why this result, in fact,...
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main()...
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main() { int i = 2, j = 2 + i, k; k = i * j; printf("%d\n", k + j); return 0; } 2) #include <stdio.h> int main() { int i = 2, j = 2 + i, k = j / 2; if (k == 1) { printf("%d\n", j) k = k * 2; if ( k == j) { printf("%d\n|, j); }...
My java program will not compile. I receive the following error; Test.java:9: error: incompatible types: int[]...
My java program will not compile. I receive the following error; Test.java:9: error: incompatible types: int[] cannot be converted to int int size = new int [start]; //Java Program import java.util.Scanner; public class Test{ public static void main(String []args) { int start, num; System.out.println("Enter the number of elements in a array : "); start = STDIN_SCANNER.nextInt(); int size = new int [start]; System.out.println("Enter the elements of array where last element must be '0' : "); for(int i = 0; i...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT