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
What changes should be made in OSI model(Open System Interconnection).
saveliy_v [14]

Answer:

Explanation:

When most non-technical people hear the term “seven layers”, they either think of the popular Super Bowl bean dip or they mistakenly think about the seven layers of Hell, courtesy of Dante’s Inferno (there are nine). For IT professionals, the seven layers refer to the Open Systems Interconnection (OSI) model, a conceptual framework that describes the functions of a networking or telecommunication system.

The model uses layers to help give a visual description of what is going on with a particular networking system. This can help network managers narrow down problems (Is it a physical issue or something with the application?), as well as computer programmers (when developing an application, which other layers does it need to work with?). Tech vendors selling new products will often refer to the OSI model to help customers understand which layer their products work with or whether it works “across the stack”.

Layer 7 - Application

To further our bean dip analogy, the Application Layer is the one at the top--it’s what most users see. In the OSI model, this is the layer that is the “closest to the end user”. It receives information directly from users and displays incoming data it to the user. Oddly enough, applications themselves do not reside at the application layer. Instead the layer facilitates communication through lower layers in order to establish connections with applications at the other end. Web browsers (Google Chrome, Firefox, Safari, etc.) TelNet, and FTP, are examples of communications  that rely  on Layer 7.

Layer 6 - Presentation

The Presentation Layer represents the area that is independent of data representation at the application layer. In general, it represents the preparation or translation of application format to network format, or from network formatting to application format. In other words, the layer “presents” data for the application or the network. A good example of this is encryption and decryption of data for secure transmission - this happens at Layer 6.

4 0
2 years ago
Read 2 more answers
Witch of the following attributes of a website indicates a more reliable source for information
Arada [10]
The only one of those I would trust is the site ending with EDU I hope this helps you.
4 0
3 years ago
An example of a(n) ____ reconnaissance attack is a user who sends SQL injections to a system in hopes of generating some type of
Elden [556K]
The answer to this question is A
7 0
2 years ago
Read 2 more answers
What engine component is shown in the above Figure?
astra-53 [7]

send attached file with it


5 0
3 years ago
Read 2 more answers
A presentation on the history of the Internet would mostlikely use the ____ pattern of organizationSpatialproblem-solutionchrono
m_a_m_a [10]

Answer:

topical

Explanation:

A presentation on the history of the Internet would mostlikely use the topical  pattern of organization.

3 0
3 years ago
Other questions:
  • The following algorithm should output the t times table in the format:
    6·1 answer
  • The max-age attribute of a cookie is specified in
    13·1 answer
  • The number of bits per pixel is called what
    7·1 answer
  • Wich technology can a website use to allow you to listen to a concert live over the internet?
    10·1 answer
  • Instructions:Select the correct answer.
    8·2 answers
  • Assume that we have an application with a total of 500,000 instructions where 20% of them are the load/store instructions with a
    14·1 answer
  • What is a Hard Drive
    13·1 answer
  • What symbol do we use to denote a character?
    14·1 answer
  • How to scan a screenshot on Brainly?
    9·2 answers
  • What is not recyclable in a<br> hybrid car<br> hydrogen car<br> petrol car
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!