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
Which option best describes a trustworthy person?
jasenka [17]
<span>A person who babysits your kids or who you tell your secrets to.



A example since you dont have choices</span>
5 0
4 years ago
Read 2 more answers
Software that enables you to display and interact with text and other media on the web is a web ________.
a_sh-v [17]
It's a web site or web page
5 0
4 years ago
Which alignment aligns text to the left and right side margins?
FrozenT [24]

Answer:

I have the same question but a little different I’m sorry that this is useless to you question but it’s not letting me ask my question. Sorry again-

Explanation:

What is a software system designed to locate information on the World Wide Web? Search browser Search engine Search keyword Search results

5 0
3 years ago
List the components of a typical operating system and summarize the role of each in a single phrase.
yanalaym [24]

Answer:

The answer is below

Explanation:

There are several components of operating systems, this may be based on the specific types of Operating systems. However, here are some of the major components.

1. Kernel: it delivers the primary level of control on all the computer peripherals.

2. Process Execution: it serves as a connection between the hardware and application program

3. Interrupt: it provides a dependable technique for the OS to transmit & respond to their surroundings.

4. Memory Management: it regulates main memory and then moves processes between disk & main memory during implementation.

5. Multitasking: it interprets the activities of many independent computer programs on a similar computer system.

6. Networking: it defines the interaction of processor through communication lines

7. Security: it protects the activities of other processes going in the system

8. User Interface: it provides permission for a computer operator to get the information.

3 0
3 years ago
Name the tools and materials used in electrical installation job below.​
kow [346]
Voltage tester, Circuit finder, Screwdrivers and nut drivers specific to electricians, Pliers, measuring tape
8 0
3 years ago
Other questions:
  • Which formula returns TRUE, if the value in cell B1 is less than 40 and the value in C1 is less than 100?
    7·2 answers
  • Using the _______ list, you can select the number of photos that will appear on each slide.
    14·1 answer
  • Presses the Schedulr app icon Selects the list item for CSCI 448 Presses the "View Classroom on Map" button While only performin
    11·1 answer
  • Which two options are negotiated via ncp during the establishment of a ppp connection that will use the ipv4 network layer proto
    7·1 answer
  • IPv6 is being developed in order to:
    15·1 answer
  • 2min speech on can teachers be replace by technology​
    5·1 answer
  • When code is compiled it
    6·2 answers
  • Need answer ASAP. I’ll mark brainliest if correct
    7·1 answer
  • For each situation, provide a pseudocoded algorithm that would accomplish the task. Make sure to indent where appropriate.Situat
    10·1 answer
  • 1.Which thematic group uses technology to direct the behavior of dynamical systems, ensuring that they behave in a predictable m
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!