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
In what areas is leslie's underspending hurting her
azamat

Answer:

in what areas is leslie's underspending hurting her

Savings

Housing - Yes as investing in housing is a long term saving

Utilities - no this is not a saving, underspending will increase saving

Transportation - no this is not a saving, underspending will increase saving

Groceries - no this is not a saving, underspending will increase saving

Retirement - Yes as investing in Retirement  is a long term saving

Debt Payment -Yes as investing in Debt Payment  is a long term saving

Phone, Cable, Internet - no this is not a saving, underspending will increase saving

Medical Expenses - no this is not a saving, underspending will increase saving

Miscellaneous - accordingly as explained above for each option.

Dining out- no this is not a saving, underspending will increase saving

Explanation:

Please check the answer section.

7 0
3 years ago
In which area of engineering does material selection play a vital role a design optimization b forensic engineering c mechanical
const2013 [10]
D. Prototyping. This is because a prototype is basically a replica of the original one and in order to find out what all we need to add in our original, material selection plays a vital role in prototypes.
4 0
3 years ago
Why is a DNS cache poisoning attack dangerous? Check all that apply. A. Errrr...it's not actually dangerous. B. It allows an att
larisa [96]

Answer:

(B) It allows an attacker to redirect targets to malicious webserver.

(D) It affects any clients querying the poisoned DNS server.

Explanation:

DNS cache poisoning is a serious type of attack that is designed to exploit the vulnerabilities inherent in a Domain Name Server (DNS) where a user is redirected from a real server to a fake one. It is also called DNS spoofing.

Normally, when your browser tries to visits a website through a given domain name, it goes through the DNS server. A DNS server maintains a list of domain names and their equivalent Internet Protocol addresses. This server (DNS) then responds to the request with one or more IP addresses for the browser to reach the website through the domain name.

The computer browser then get to the intended website through the IP address.

Now, if the DNS cache is poisoned, then it has a wrong entry for IP addresses. This might be via hacking or a physical access to the DNS server to modify the stored information on it. Therefore, rather than responding with the real IP address, the DNS replies with a wrong IP address which then redirects the user to an unreal website.

Although they might not be able to control your computer remotely as long as you are not trying to visit a web page via the poisoned information, there are other dangers attached to this type of attack.

Once the DNS server has been poisoned, any client trying to query the server will also be affected since there is no direct way of knowing if the information received from the server is actually correct.

4 0
3 years ago
You saved a file on drive C go your computer. You want to find and open the file. Which of the following programs will you use t
Sindrei [870]

Group of answer choices.

A. Spreadsheet program

B. Microsoft Windows Explorer

C. Word-processing program

D. Notepad

Answer:

B. Microsoft Windows Explorer

Explanation:

A software can be defined as a set of executable instructions (codes) or collection of data that is used typically to instruct a computer how to perform a specific task and to solve a particular problem.

In this scenario, you saved a file on drive "C" of your computer. The software program or application which you would use to find and open the file is Microsoft Windows Explorer.

The Microsoft Windows Explorer is an inbuilt resources that avails the end users the ability to perform various operations on a file and it provides the folder paths used for the storage of user files. It is the default program for file and folder documents on a computer system.

6 0
3 years ago
Which of the following is a school-to-work program that provides the student with paid employment, school credit, and school gra
vovangra [49]

Cooperative education program

6 0
2 years ago
Read 2 more answers
Other questions:
  • Which option is referred to by the Animals tag?
    5·1 answer
  • PLEASE HURRY
    6·1 answer
  • All the computers in this type of network are connected to two other computers.
    12·1 answer
  • Odbc works on the ____ operating system.
    5·1 answer
  • Is it better to meet online or offline<br> (Please answer QUICK)<br><br> Thanks :')
    5·2 answers
  • For the function definition int SomeFunc( /* in */ int alpha, /* in */ int beta ) { int gamma; alpha = alpha + beta; gamma = 2 *
    6·2 answers
  • Return a version of the given string, where for every star (*) in the string the star and the chars immediately to its left and
    11·1 answer
  • I need help about computer program. Solve C language code...... please​
    7·1 answer
  • How would you open the web browser in Linux and still have access to the Linux terminal?
    14·1 answer
  • Difference between centralized and decentralized processing in computer
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!