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
If you're searching for a date and a product at the same time, you're running a _______ query. A. Complex B. Select C. Parameter
Andrews [41]

If you're searching for a date and a product at the same time, you're running a _______ query. A. Complex B. Select C. Parameter D. Range                                                                                                                                                                                                                                                         A. Complex

6 0
3 years ago
It is 10PM and you are inside in the middle of a large building. Your cell phone is dead so you cannot use wifi or cell signals
kupik [55]

<em>The answer is: your GPS unit cannot send signals to the satellite when it cannot reach it by line of sight. </em>

<em> </em>

<em>GPS signals are based on frequencies that can be blocked by solid objects (like walls and roofs). A GPS device is using a series of satellites to detect and see where it is physically located. These frequencies are sent from these plates (satellites) and we cannot expect it to go through all kinds of barriers. When you use a GPS inside a building, a wide variety of physical barriers and potential interference sources make it difficult for the device to detect your location accurately. </em>

<em> </em>

<em />

4 0
3 years ago
A _is a short descriptive label that you assign to webpages, photos,
Nitella [24]
Looks like you already answered your question? It’s the a tag ()
5 0
3 years ago
1,
sashaice [31]

Answer:

Match the methods:

See attached file

---------------------------------------------------------------------------------------------------------------------------------------

2)

Methods are public, and instance variables are private in common pattern of a class definition program.

So, the correct option is (C).

- -----------------------------------------------------------------------------------------------------------------------------------------

3) Java code:

//Create a Throttle called quiz with 100 positions<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Throttle quiz = new Throttle(100);

//Method that shifts quiz's flow to the halfway

quiz.shift(50);

//Display the current flow from quiz.

System.out.println(quiz.getflow());

-------------------------------------------------------------------------------------------------------

4)

Assume that the Foo class does not have a clone method. Then x is set to refer to a copy of y's object for an assignment x=y; in two Foo objects

.

So, the correct option is (A)

-----------------------------------------------------------------------------------------------------------------------------------------

5)

The correct option is

A)

mower.top and copter.top will always be two separate instance variables.

Explanation:

8 0
3 years ago
To create a nonlinear presentation that had external links the designer should
laila [671]

Answer:

To create a nonlinear presentation that had external links the designer should include “hyperlinks”

Explanation:

Let us understand what non-linear presentation is. It’s a reverse of linear presentation. A linear will go slide by slide, without any jump. A non-linear slide is a type of presentation prepared when the flow of slide is not much important, and the presenter can jump to any of the slide from any slide. This is done thorough two ways. 1. Hyperlink 2. Action button

We must include hyperlinks or action buttons where it allows us to toggle or navigate to any of the slide within the file. The hyperlink can also be added to move the control to a website.

6 0
4 years ago
Other questions:
  • Initially, later, and finally are examples of what kind of words
    9·1 answer
  • ¿Es especial que mi cumpleaños sea el día de San Valentín?<br><br> si o no
    11·2 answers
  • the microsoft excel application is a _____ program. database word-processing spreadsheet desktop-publishing
    8·1 answer
  • Which design element is used to convey smoothness or roughness in a design
    12·1 answer
  • How many people employed in the United States work in a job related to digital media?
    12·1 answer
  • How do you copy and paste a screenshot on an hd computer
    12·2 answers
  • 2. Integer plot function (find a smart way to code big integers) Write a program BigInt(n) that displays an arbitrary positive i
    8·1 answer
  • How will you apply what you have learned in our topic today in a real life situation? Show your answers in the acronyms provided
    6·1 answer
  • Python 3 (not java)1.Assume that word is a variable of type String that has been assigned a value. Write an expression whose val
    14·1 answer
  • In a mobile phone network, how many times as strong would
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!