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
The overall cost of wiring in addressable fire alarm system is significantly cheaper than the conventional one. Why is it so?
stellarik [79]

Answer:

Yes, The overall cost of wiring in addressable fire alarm system is significantly cheaper than the conventional one.But the addressale fire alram system is more reliable than a conventional system.

Explanation:

Conventional systems are hardware-based and use analog technology. where addressable fire alarm use digital technology. addressable system is generally more reliable than a conventional system mainly due to how the different systems are wired. With a conventional system, if a device’s wire is damaged or severed, its signal and the signal of other devices down the line cannot be transmitted to the control panel.

With an addressable system, both ends of the wire connect to the control panel. Therefore, if one end becomes damaged or severed, signals can still reach the control panel through the other end of the loop. In addressable systems, a device can be removed or disabled and it will not affect the other devices in the loop.

7 0
3 years ago
How to change my ip address
Ostrovityanka [42]

you can use a vpn (virtual proxy network) that is the easiest way and the fastest

8 0
3 years ago
Read 2 more answers
A customer in Lowe's needs help. Matt works in shipping and receiving. It isn't Matt job to work with the customer, but he knows
klio [65]

Answer:

40

Explanation:

hhhhhjjjj

5 0
3 years ago
Read 2 more answers
What kind of output device would not be used to output images
saveliy_v [14]

Answer:

Speakers.

Explanation: Cause they only output sound, and are devices, further more they are not used to output images, like how could speakers output images using sound? They can't.

3 0
3 years ago
Is the ipv6 address 2001:1d5::30a::1 a valid address? why or why not?
defon
<span>Not a valid IPv6 address A valid IPv6 address consist of 8 groups of 4 hexadecimal numbers separated by colons ":". But that can make for a rather long address of 39 characters. So you're allowed to abbreviate an IPv6 address by getting rid of superfluous zeros. The superfluous zeros are leading zeros in each group of 4 digits, but you have to leave at least one digit in each group. The final elimination of 1 or more groups of all zeros is to use a double colon "::" to replace one or more groups of all zeros. But you can only do that once. Otherwise, it results in an ambiguous IP address. For the example of 2001:1d5::30a::1, there are two such omissions, meaning that the address can be any of 2001:1d5:0:30a:0:0:0:1 2001:1d5:0:0:30a:0:0:1 2001:1d5:0:0:0:30a:0:1 And since you can't determine which it is, it's not a valid IP address.</span>
6 0
3 years ago
Other questions:
  • On an Android device, where can a user find the correct app to use to sync contacts and apps among devices?
    10·1 answer
  • How can you autohide the taskbar in Windows 10?
    8·2 answers
  • How does LinkedIn differ from other popular social media platforms? What are the similarities?
    6·1 answer
  • Why does Zoologist have no work experience in a related occupation?
    5·1 answer
  • In Alphatech Systems, email software screens incoming messages by organizing them into mailboxes and identifying junk mail. As a
    13·1 answer
  • 1. Itemise the order in which BASIC executes arithmetic operation.
    13·1 answer
  • You are having problems on your Windows 7 computer and you pull up Device Manager to see if there are any alerts. Two of your de
    11·1 answer
  • IOS jail broken or Android unrooted which is better to hack with
    6·1 answer
  • Programmers should strive to _____. increase coupling increase cohesion both of the above neither a nor b
    7·1 answer
  • Definition of digital
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!