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.
Our MIPS assembly version will “compile” the following C program: #include void Compare(int b1, int h1,...
Our MIPS assembly version will “compile” the following C program: #include void Compare(int b1, int h1, int b2, int h2); int Area(int b, int h); int main(int argc, char **argv) { int base1, base2, height1, height2; base1=10; base2=12; height1=8; height2=7; Compare(base1, height1, base2, height2); return 0; } void Compare(int b1, int h1, int b2, int h2) { int A1=Area(b1, h1); int A2=Area(b2, h2); if (A1>=A2) printf("Area1 is greater than Area2.\n"); else printf("Area2 is greater than Area1.\n"); } int Area(int b,...
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; }
import kotlinx.coroutines.* // TODO 1 fun sum(valueA: Int, valueB: Int): Int {     return 0 }...
import kotlinx.coroutines.* // TODO 1 fun sum(valueA: Int, valueB: Int): Int {     return 0 } // TODO 2 fun multiple(valueA: Int, valueB: Int): Int {     return 0 } fun main() = runBlocking {     println("Counting...")     val resultSum = async { sum(10, 10) }     val resultMultiple = async { multiple(20, 20) }     // TODO 3     println() } TODO 1: Change it to suspend function with the following conditions: Has a waiting time of 3 seconds...
(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...
#include <stdio.h> #include <ctype.h> int main(void) { int ch; unsigned long int charcount=0, wordcount=0, linecount=0; while((ch=getchar())!=EOF){...
#include <stdio.h> #include <ctype.h> int main(void) { int ch; unsigned long int charcount=0, wordcount=0, linecount=0; while((ch=getchar())!=EOF){ if(ch==' ' || ch=='\n' || ch=='\t' || ch=='\0' || ch=='\r') { wordcount++; } if(ch=='\n' || ch=='\0') { linecount++; } charcount++; } printf("%lu %lu %lu\n", charcount, wordcount, linecount); getchar(); return 0; } When my code reads a blank line, it increment my wordcount by one. How can I fix this problem? Could you help me with this problem?
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 : " <<...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT