Schrift
[thread]9172[/thread]

Script nicht ohne Admin-Rechte starten



<< >> 6 Einträge, 1 Seite
Gast Gast
 2007-07-09 19:10
#78317 #78317
hi,
ich möchte das sich mein script beendet wenn es keine admin rechte hat... wie geht das?
MisterL
 2007-07-09 19:38
#78318 #78318
User since
2006-07-05
334 Artikel
BenutzerIn
[default_avatar]
Unter *nix geht das so:
Code: (dl )
1
2
3
4
5
6
7
#
# Check for root
#
if [ `id -u` != "0" ]; then
echo -e "You should be root to start this program"
do_exit ${ERR_no_suid}
fi
(hab ich aus einem Installationsskript für ein SAP System entnommen)
“Perl is the only language that looks the same before and after RSA encryption.”
Linuxer
 2007-07-09 19:47
#78319 #78319
User since
2006-01-27
3890 Artikel
HausmeisterIn

user image
perldoc perlvar listet einige Variablen dazu auf, vielleicht kommt damit um das `id -u`vorbei:
Quote
...
# $REAL_USER_ID
# $UID
# $<

The real uid of this process. (Mnemonic: it's the uid you came from, if you're running setuid.) You can change both the real uid and the effective uid at the same time by using POSIX::setuid(). Since changes to $< require a system call, check $! after a change attempt to detect any possible errors.

# $EFFECTIVE_USER_ID
# $EUID
# $>

The effective uid of this process. Example:

$< = $>; # set real to effective uid
($<,$>) = ($>,$<); # swap real and effective uid

You can change both the effective uid and the real uid at the same time by using POSIX::setuid(). Changes to $> require a check to $! to detect any possible errors after an attempted change.

(Mnemonic: it's the uid you went to, if you're running setuid.) $< and $> can be swapped only on machines supporting setreuid().

...
\n\n

<!--EDIT|Linuxer|1183996790-->
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!
moritz
 2007-07-10 11:05
#78320 #78320
User since
2007-05-11
923 Artikel
HausmeisterIn
[Homepage]
user image
In diesem Fall ist wohl die Effective User-ID das, was man prüfen möchte.
RPerl
 2007-07-12 15:40
#78321 #78321
User since
2006-11-26
384 Artikel
BenutzerIn

user image
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl

use strict;
use warnings;

my $id = '^uid=0';
my $testid = qx{/usr/bin/id};

if ( $testid !~ /$id/ ) {
    print "[-] access denied!";
       exit;
} else {
    print "[+] startin\' script";
    #&foo();
}


quick && dirty
bloonix
 2007-07-12 16:54
#78322 #78322
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hmmm wie wäre es, wenn man die Rechte des Skripts so setzt, dass nur
der Admin es ausführen darf?
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.
<< >> 6 Einträge, 1 Seite



View all threads created 2007-07-09 19:10.