http://www.pronix.de -> Forum -> Administration, Konfiguration

Forum: Administration, Konfiguration

Moderatoren: Herb, Martin Conrad

Thema: /etc/shadow

  • (nur registrierte Mitglieder)

/etc/shadow

Patrick am 17.12.2010 um 09:40

Die /etc/shadow enthält u.a. einen Wert (5. Stelle), der die Gültigkeit eines Kennwortes in Tagen festlegt.
Zudem gibt es einen Wert (6. Stelle), der festlegt, wieviele Tage vor Ablauf der Benutzer beim Login gewarnt werden soll.

Afaik wird der Benutzer nur bei einem erfolgreichen Login informiert.
Ich möchte diese Info nun aber gerne automatisch erkennen und auswerten.
Gibt es dafür linuxeigene Lösungen?

--
To follow the path: look to the master, follow the master, walk with the master, see through the master, become the master.

 

Re: /etc/shadow

broesel (webmaster) am 19.12.2010 um 16:10

Vielleicht hilft Dir sowas weiter:

sudo chage -l <user>

Mit grep, cut, date und mail sollte man sich in Kürze etwas Brauchbares zusammenbasteln können.

Gruss,
Philip

--
The C Programming Quiz (externer link) - bitte Fragen einreichen :)

 

Re: /etc/shadow

Patrick am 19.12.2010 um 18:48

Ich habe grade kein Linux zur Hand und werde es morgen früh im Betrieb testen.
Danke Philip Grafik: Smilie Zwinker

--
To follow the path: look to the master, follow the master, walk with the master, see through the master, become the master.

 

Re: /etc/shadow

Martin Conrad (webmaster) am 19.12.2010 um 20:10

Zitat:

Ich möchte diese Info nun aber gerne automatisch erkennen und auswerten.
Gibt es dafür linuxeigene Lösungen?


linuxeigen wüsste ich keine, aber du kannst dir mit getpwnam() kurz einen kleinen vierzeiler tippen, der das für dich rausholt. getpwnam ist POSIX, der Krempel funktioniert dann also auch auf anderen Systemen.

Bis denne

Martin

--
0xC0FFEE

 

Re: /etc/shadow

broesel (webmaster) am 20.12.2010 um 01:27

Urlaub!


#!/bin/bash

# Returns chage output's value of the first line matching $2 for user $1
chage_grep() {
        REPLY=$(sudo chage -l "$1" | grep "$2" | head -n 1 | cut -d\: -f2 | tr -d ' ')
}

# Returns the number of days until $1's password expires.
# A negative value denotes that the expiry date is in the past.
expires() {
        chage_grep $1 "Password expires"
        expy=$REPLY
        curr=$(date "+%F")

        # Use this for testing:
        if [ $1 == "nobody" ]; then expy="Dec 23, 2010"; fi

        if [ "$expy" == "never" ]; then
                REPLY="";
        else
                # convert to seconds
                expy=$(date -d "$expy""+%s")
                curr=$(date -d "$curr""+%s")

                # distance in days
                REPLY=$[($expy - $curr) / 86400]
        fi
}


for user in $(cat /etc/passwd | cut -d\: -f1); do
        # number of days until $user's password expires
        expires $user
        expy=$REPLY

        # number of days of warning before password expires
        chage_grep $user "warning"
        warn=$REPLY

        if [ -z "$expy" -o "$warn" == "-1" ]; then continue; fi

        if [ $expy -le $warn ]; then echo "User $user expires in $expy days."; fi
done


Jetzt weiß ich wieder, warum ich bash hasse...

Gruss,
Philip

--
The C Programming Quiz (externer link) - bitte Fragen einreichen :)

 
  • (nur registrierte Mitglieder)