Sponsored Content
Full Discussion: Issues with setting Aliases
Top Forums Shell Programming and Scripting Issues with setting Aliases Post 302966186 by Don Cragun on Tuesday 9th of February 2016 06:16:59 AM
Old 02-09-2016
Hi mohtashims,
I agree with everything bakunin, RudiC, and MadeInGermany said.

An alias won't keep users from invoking /bin/rm -f .... A shell function won't keep users from invoking /bin/rm -f ....

But, of course, there is something you can do. Replace /bin/rm with your own version of rm that generates an error message whenever anyone tries to use the -f option. You will get exactly what you want. System maintenance procedures may stop working. System boot procedures may stop working. User shell scripts may stop working. So what; you have made sure that no user is able to avoid an error message when removing a temp file that might not have been created in the first place. Why should they want to do that when they can rewrite their scripts so they will work on your perfected operating system even through their scripts work perfectly on every other POSIX-conforming system in the world.

After modifying rm, are you going to rewrite the manual pages for rm and any utility on your system that might invoke rm with a -f option as well? Or, do you just plan to tell your users that the implementation-supplied man pages are broken and that you have "fixed" the system to work more safely? If third-party software doesn't work on your system because you have fixed rm, are you going to tell those third-party suppliers to "fix" their code to work on your system; or are you going to tell users that they just shouldn't buy from those suppliers because the programmers who wrote their code used an option that you have decided is too dangerous to be allowed to be used on your "improved" system.

And, if a user wants to remove a read-only file from your system, obviously users on your system should learn to use the much safer sequence of commands:
Code:
chmod 644 file
/bin/rm file

instead of the dangerous code:
Code:
rm -f file

After all, typing two or three times as much isn't much more likely to introduce typographic errors is it? And, running two utilities instead of one and accessing a file twice instead of once won't affect system performance, will it?

Or, maybe you want your version of /bin/rm to always behave as if the -i option is in effect. Of course, if you do that, you won't be able to remove any files in a non-interactive script anymore, but so what? Why should anybody be allowed to remove any file without interactively confirming that they really wanted to remove those files? After all, there is no reason why anyone should be allowed to run a cron job that removes temporary files it uses, is there?

And, what about the yes utility? Are you going to remove it to so users can't use:
Code:
yes|rm -i /dir/* > /dev/null

(which they will quickly learn to do since the -f option is no longer available). And, after you remove the yes utility, are you going to fix all of the shells on your system so your users can't use a while loop with echo or printf to simulate the yes utility? Are you going to get rid of the C and C++ compilers so users can't write their own rm utilities and their own yes utilities? And, are you going to remove the chmod, find, rmdir, and unlink utilities from your system so they can't replace:
Code:
rm -rf file...

with the MUCH less efficient:
Code:
find file... ! -type d -exec chmod 600 {} \; -exec unlink {} \;
find file... -type d -depth -exsec chmod 600 {} \; -exec rmdir {} +

? After all, UNIX, Linux, and BSD systems are known for providing lots of ways to do some pretty common things (like remove a file).

If you could fix alias to work the way you want it to, would you remove unalias from all of the shells on your system so users can't get rid of your fix? And, would you fix alias to that an alias for rm can't be redefined?

If you treat your users like foolish children who can't be trusted to use standard operating system features, you will quickly learn that foolish children can turn into rebellious teenagers. And those rebellious teenagers will find ways to get around your restrictions until they are able to move out of your realm of control and work on an unmodified system where they can do their jobs without having to work around your "system improvements". (And don't think that your foolish and rebellious children won't talk to each other and pass around ways to get around your restrictions.)

So, yes, there are lots of things you can try to disable the rm -f option. But, you can't keep users from getting around anything you do. And, you can't keep users from accidentally removing a file (or thousands of files) if they aren't careful typing commands into a shell and when they are responding to prompts issued by every utility they invoke.

You will eventually find out that if you modify your system to become foolproof, a new breed of fool will start using your system.
These 2 Users Gave Thanks to Don Cragun For This Post:
 

8 More Discussions You Might Find Interesting

1. Programming

aliases

Hi. I have a C program that is using the **environ pointer and I am trying to set up aliases for a system("/bin/ksh") call. This works for other environment variables but not for the aliases. Does anyone know if this can be done? Thanks ahead of time. (1 Reply)
Discussion started by: mluey61
1 Replies

2. UNIX for Dummies Questions & Answers

aliases

Is there a way to view what aliases are running on a given session? (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

3. Shell Programming and Scripting

etc aliases

Hello: i have several server with own etc aliases. right now i want to combine it all into a general etc aliases in a new freebsd server. cause it consist hundred thousand of record user inside how to make a shell script to combine it or configure it. all etc aliases record example: ... (0 Replies)
Discussion started by: peterLfs
0 Replies

4. UNIX for Dummies Questions & Answers

Setting aliases

How come if I set an alias as such: alias dt 'date "+%Y-%m-%d %H:%M:%S"' it will work as intended, ie the command 'dt' does prompt the date and time, but not when invoked through a script as such: #!/bin/sh alias dt 'date "+%Y-%m-%d %H:%M:%S"' The OS is FreeBSD 7.1. Thanks in advance (4 Replies)
Discussion started by: figaro
4 Replies

5. Solaris

Help with beginner issues setting up ZFS??

Hi, I'm new to Solaris 11. The goal is to set up a ZFS raid-Z2 NAS. These are the instructions I've been trying to follow, with no luck: "Setting Up an OpenSolaris NAS Box: Father-Son Bonding" (not allowed to post URL) Issues: 1) Root access is evidently required but I don't... (8 Replies)
Discussion started by: lakedude
8 Replies

6. UNIX for Advanced & Expert Users

Issues in setting up remote syslogging

Hello, I am using Ubuntu Linux and having problems in setting up remote syslogging. Appreciate your help on this. On the server unix host, I have made following changes. uncommented following lines in /etc/rsyslog.conf $ModLoad imudp $UDPServerRun 514 Now i am trying to run rsyslog in... (0 Replies)
Discussion started by: ravi.videla
0 Replies

7. Solaris

Is there a difference between setting a user as nologin and setting it as a role?

Trying to figure out the best method of security for oracle user accounts. In Solaris 10 they are set as regular users but have nologin set forcing the dev's to login as themselves and then su to the oracle users. In Solaris11 we have the option of making it a role because RBAC is enabled but... (1 Reply)
Discussion started by: os2mac
1 Replies

8. Proxy Server

Samba on AIX, issues setting read-only flag on files?

Hello, I am having issues setting the "read-only" flag via Windows Explorer on my AIX Samba share... I have on my AIX 7.1 system installed Samba 3.6.24 and configured, joined to our Windows domain successfully. The samba binaries I got from perzl.org/aix In my smb.conf I have... ... (1 Reply)
Discussion started by: c3rb3rus
1 Replies
All times are GMT -4. The time now is 06:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy