LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 05-07-2012, 10:15 AM   #1
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 460

Rep: Reputation: 39
Is This An Error?


i am going over some scripts someone else did. am i correct, it should be "<=500" and not ">=500" ??

Code:
Make sure system accounts cannot be accessed by using the following script:

#!/bin/bash
for user in ` awk -F: ' ($3 >= 500) {print $1 }' /etc/passwd; do 
     if [ $user != "root" ]
     then
          /usr/bin/usermod -L $user
          if [ $user != "sync" && $user != "shutdown" && $user != "halt" ] 
          then
               /usr/sbin/usermod -s /sbin/nologin $user 
          fi
     fi 
done
 
Old 05-07-2012, 11:18 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Slackware
Posts: 12,216
Blog Entries: 2

Rep: Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882
As I understand it the statements filters out all users with an UID below 500, which usually are system users. Most distributions nowadays use even only the numbers from 1000 upwards for non-system users.
 
Old 05-07-2012, 12:05 PM   #3
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 460

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by TobiSGD View Post
As I understand it the statements filters out all users with an UID below 500, which usually are system users. Most distributions nowadays use even only the numbers from 1000 upwards for non-system users.
in awk, ($3 >= 500) says $3 less than 500 ???
 
Old 05-07-2012, 12:18 PM   #4
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 621

Rep: Reputation: 245Reputation: 245Reputation: 245
Quote:
Originally Posted by Linux_Kidd View Post
in awk, ($3 >= 500) says $3 less than 500 ???
No. Please read the TobiSGD's post more carefully. The script prints all users with UID greater than or equal to 500. that means that it filters out (that is, does not print users with UID below 500).
 
Old 05-07-2012, 12:18 PM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Slackware
Posts: 12,216
Blog Entries: 2

Rep: Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882
No, it says to only print the th users with an UID >=500, which is effectively filtering out anything below 500.
 
Old 05-07-2012, 12:42 PM   #6
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 460

Original Poster
Rep: Reputation: 39
i know what the awk does, was asking in the context of the script. so in the title of the script it's wrong then. as is it will lock all accounts >=500
 
Old 05-07-2012, 01:18 PM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Slackware
Posts: 12,216
Blog Entries: 2

Rep: Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882
OK, I have not really looked at that part, since you emphasized the conditional statement. No, it will not really lock the accounts, but do something similar: It disables the passwords for those users and set their login shells to /sbin/nologin.
This may not be what is intended (in this case most likely), but it is dependent on the context. This will for example enable password-less access to a FTP server for all users without letting them connect via SSH or log in locally.
 
Old 05-07-2012, 02:34 PM   #8
sundialsvcs
Senior Member
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 4,554

Rep: Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640
Let's take a closer look at this particular "magic voodoo incantation":

Code:
` awk -F: ' ($3 >= 500) {print $1 }' /etc/passwd`
Notice first of all the back-tick character. This means that the shell is to execute the enclosed command, then do something with every line that this command generates. [i](Note that I added one tick. And if you live in the deep South in the US where ticks are a curse this time of year, I apologize in advance. )

So, why don't you start by excising that particular line of text out of the script and type it in directly on the command-line. If you hold your mouth in just the right position on a night precisely the right phase of the moon, at a crossroads after turning widdershins thrice, (which is why I hate this sort of magick...) you will see that this command tells awk to read /etc/passwd and to execute its own "tiny little program" against it: a "tiny little program" that, for every line in the aforesaid file in which the third blank-delimited token (taken as an integer) is greater than or equal to 500, will print out the content of the first token (for consumption by our shell script).

The line is therefore probably correct.

The trouble, for you and for anyone else, is that this kind of coding is very obtuse: when coded in exactly the right way and run under exactly the right conditions, it "works, sort of."

Last edited by sundialsvcs; 05-07-2012 at 02:35 PM.
 
Old 05-07-2012, 03:00 PM   #9
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 460

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by sundialsvcs View Post
Let's take a closer look at this particular "magic voodoo incantation":

...
The line is therefore probably correct.
1. ok, i didnt write the code, just reviewing it.
2. i dont think it is correct.

the title of the script is
"Make sure system accounts cannot be accessed by using the following script:"
which i belive is UID <=500 and not >=500 (rhel 5.x)

thats what i am asking......
 
Old 05-09-2012, 05:26 AM   #10
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 460

Original Poster
Rep: Reputation: 39
bump,
any answers on my post #9 ??
 
Old 05-09-2012, 05:41 AM   #11
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 621

Rep: Reputation: 245Reputation: 245Reputation: 245
Probably the intention of the author was to print entries with "$3 < 500", because otherwise {,s}he would not check whether or not the $user is 'root' in the next line since this would have been filtered out by awk. So it probably is an error.
 
Old 05-15-2012, 01:52 PM   #12
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 535

Rep: Reputation: 90
What about post #2? Is the limit <= 1000 for system files?

In this URL, (ClearOS - listed in DistroWatch)
http://www.clearfoundation.com/docs/..._gids_and_rids
UID/GID RID Purpose Examples
System Users 0-499 n/a System user accounts root, apache, mysql
System Groups 0-499 n/a System group accounts lp
Normal Users 500-999 n/a User accounts outside of LDAP devel

OK
 
Old 05-15-2012, 02:00 PM   #13
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Slackware
Posts: 12,216
Blog Entries: 2

Rep: Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882Reputation: 2882
There is actually no guideline for the limit between system users and normal users. It is totally dependent on the distro developers mind. For example, Fedora has used a limit of 500 for a long time and recently switched to 1000.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Google-Chrome Error (Error 9 (net::ERR_UNEXPECTED): Unknown error) smoooth103 Slackware 4 12-04-2010 07:42 PM
[SOLVED] php5 ./configure error: (FILENAME=- FNR=27) fatal error: internal error richinsc Linux - Software 2 07-08-2010 09:20 AM
Memory error: extended error chipkill ecc error rajivdp Linux - Hardware 1 12-07-2009 08:26 AM
Sendmail: eocket wedge , 504 error , dsn error, mail relay connection error djcs Debian 0 03-03-2009 12:41 AM
Suse CUPS error: cups(File)DoRequest error:client-error-bad-request smdonelan Linux - Hardware 6 04-17-2007 06:46 PM


All times are GMT -5. The time now is 10:07 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration