1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
natta225 [31]
3 years ago
12

Write a C program that will allow you to add messages to a file that has NO permissions for any user. A Unix system has many fil

es that have sensitive information in them. Permissions help keep these files secure. Some files can be publicly read, but can not be altered by a regular user (ex.: /etc/passwd). Other files can't be read at all by a regular user (ex.: /etc/shadow). The program you develop should take a message given as a command line argument and append it to a file (also specified on the command line). The file should have no permissions, both before and after the message is appended. Of course, the file should be owned by you. Your program should also have a -c option that will clear the file before the message is appended. Algorithm Check to see if the output file exists. If it doesn't, create it. Life is simpler if a newly created file is closed at the end of this step. Check the permissions of the output file. If any permissions exist, print a useful error message and exit. Change the permissions on the file to allow writing by the user. Open the file for output. If the "-c" command line option is present, make sure the file is truncated. Write the message from the command line to the output file. Write an additional newline character so that the output has a nicer format.

Computers and Technology
1 answer:
amm18123 years ago
6 0

Answer:

see explaination

Explanation:

#include <iostream>

#include <fstream>

#include <sys/types.h>

#include <sys/stat.h>

#include <time.h>

#include <stdio.h>

#include <stdlib.h>

using namespace std;

int main(int agrc,char*argv[])

{

struct stat sb;

if(agrc != 2){

cout << "invalind command line arguments "<< endl;

return 0;

}

if (stat(argv[1], &sb) == -1) {

perror("stat");

exit(EXIT_FAILURE);

}

if((sb.st_mode & 777) != 0) {

cout<<"file has permission and its invalid"<<endl;

}

//chmod(argv[1], S_IRWXU);

int status = chmod(argv[1], 0200);

if(status){

cout<<"permission sucessfull change"<<endl;

}

ofstream myfile;

myfile.open (argv[1], ios::out | ios::app);

myfile<<argv[2]<<endl;

status = chmod(argv[1], 0000);

if(status){

cout<<"permission sucessfull change

0000"<<endl;

}

myfile.close();

cout << "thank you" << endl;

return 0;

You might be interested in
Write the translator of third generation language​
Licemer1 [7]

Answer:

Examples of common and historical third-generation programming languages are ALGOL, BASIC, C, COBOL, Fortran, Java, and Pascal.

Explanation:

A third-generation programming language (3GL) is a high-level computer programming language that tends to be more machine-independent and programmer-friendly than the machine code of the first-generation and assembly languages of the second-generation, while having a less specific focus to the fourth and fifth generations. Examples of common and historical third-generation programming languages are ALGOL, BASIC, C, COBOL, Fortran, Java, and Pascal.

6 0
2 years ago
Given that the variables x and y have already been declared and assigned values, write an expression that evaluates to true if x
Eduardwww [97]

Answer:

The expression to this question can be defined as follows:

Expression:

(x >= 0 && y<0) //check condition using AND operator

Explanation:

In the given question it is defined that x and y are an integer variable that holds some value, in which it defines a condition that checks the value of variable x is positive, and the value of y is negative.

  • To check positive value a condition is used, that checks x greater than equal to 0, and to check negative value, it uses condition, that is y is less than 0.
  • In the above condition, the AND operator is used, which executes when both conditions are true.
3 0
4 years ago
You have been hired to set up a network for XYZ Enterprises. What factors will you consider to determine the type of network nee
Margarita [4]

Answer:

I would say if it is a multiple choice

Explanation:

q3 or q5 would be the best ones to pick from in my eyes.

3 0
3 years ago
Read 2 more answers
Which of the following is not a type of user account? A. Administrator b. Guest c. Group d. Standard
Arlecino [84]
I've never heard of a group account so I'm going with.
C. Group
5 0
3 years ago
A(n) __________attack is designed to render the target unreachable by legitimate users, not to provide the attacker access to th
Nimfa-mama [501]
Denial of Service or Distributed Denial of Service.
3 0
3 years ago
Other questions:
  • You have received several trouble tickets from the employees in the warehouse for the stand-alone computers used to control vari
    14·1 answer
  • Technician A says that the last step in the diagnostic process is to verify the problem. Technician B says that the second step
    12·1 answer
  • . What may happen if a large number of computer users are attempting to access a Web site at the same
    10·2 answers
  • When a speaker is finished talking, you should allow for _____.
    14·2 answers
  • Universal Containers is tracking the interviewer's ratings of candidate in Salesforce. They would like to easily link the Candid
    5·1 answer
  • What are some effective methods for scrolling? Check all that apply.
    6·1 answer
  • How we can get NET I'D by IP Address?
    11·1 answer
  • What is a field on a table
    13·1 answer
  • What is the full form of MOS<br>​
    10·1 answer
  • Select the skill that matches the following definition.​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!