[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [linux-team] setuid ?



Cela n'a pas été vite clair pour moi non plus : il faut en fait agir à
deux moment : 

1- le programme concerné doit de façon active changer son UID
en un autre (voir plus bas, la ligne 'setuid(0);', où il demande de 
changer son UID en 0 (== root) PENDANT l'exécution) 

2- il doit en AVOIR le droit : donc 'chmod 4755 monprogramme'

J'ai testé cela avec le petit programme listé ci-dessous, appelé
'master.c' et compilé en 'master', utilisable par n'importe qui pour
lancer par exemple 'halt' au moyen de la commande  'master halt'

REM: 

si les exécutables appelés sont des shell scripts, ils doivent
débuter par '#!/bin/bash' par exemple 
(cela m'a aussi mystifié un moment : certains appels marchaient bien,
d'autres pas, or mes bash scripts étaient de simples listes d'instruction,
sans l'appel formel de bash)

'mnt a' par exemple est un petit script qui monte le floppy en /a etc. 

	Alain




=====================================================%<==================
#include <stdio.h>
#include <strings.h>
/* cc -o master master.c; chmod 4711 master  */

char *env[] = { "PATH=/bin:/usr/bin:/usr/sbin/", NULL};

int main(int argc, char *argv[])  {
  int ok = 0; 
  int silent = 0;
  int ptr = 1; 

  if (argc < 2 )  {
    	fprintf(stderr,"Usage: %s [-s] {reboot|halt|..}  A.Empain'98\n   -s : silent\n",argv[0]);
	exit(1);
  }
  if (argc > 2)  {
        if (strcmp(argv[1],"-s") == 0) {
            silent=1;
	    ptr=2;
        }
  }
  else  {
	ptr=1;
  }

/* ----------------------------------------------*/
                   setuid(0);
/* ----------------------------------------------*/

  if (strcmp(argv[ptr],"halt") == 0)  {
        if (silent == 0) fprintf(stderr,"..HALT !\n");
	execle("/sbin/shutdown","HALT","-h","now", (const char *) NULL,
&env);
	ok = 1;
  }
  if (strcmp(argv[ptr],"reboot") == 0)  {
        if (silent == 0) fprintf(stderr,"...REBOOT !\n");
	execle("/sbin/shutdown","REBOOT","-r","now", (const char *) NULL,
&env);
	ok = 1;
  }
  if (strcmp(argv[ptr],"cal") == 0)  {
        if (silent == 0) fprintf(stderr,"...Providing cal info\n");
	execle("/usr/bin/cal"," xxx"," 12"," 1998", (const char *) NULL,
&env);
	ok = 1;
  }
  if (strcmp(argv[ptr],"mnt") == 0 )  {
        if (silent == 0) fprintf(stderr,"...Mounting the floppy at /a\n");
	execle("/home/sys/mnt","MOUNT",argv[ptr+1], (const char *) NULL,
&env);
	ok = 1;
  }
  if (strcmp(argv[ptr],"umnt") == 0 )  {
        if (silent == 0) fprintf(stderr,"...UnMounting the floppy from
/a\n");
 	execle("/home/sys/umnt","UMOUNT",argv[ptr+1], (const char *) NULL,
&env);    
	ok = 1;
  }
  /* -------------------------------------------------------*/
  /* -------------------------------------------------------*/
  if ( ok == 0 )  {
         fprintf(stderr,"%s: invalid argument\n", argv[0]);
	 exit(2);
  } 
}
==========================================================================

--------------------------------------------- 
Dr Alain EMPAIN, Informatics, Site Master
   National Botanic Garden of Belgium
   B-1860 MEISE, Belgium 
Phone: +32 2 2693905   Fax: +32 2 2701567 
Home:  +32 85 512341,   celine@ping.be


On Fri, 12 Mar 1999, LOUVIAUX Vincent wrote:

> j ai du mal à comprendre le setuid
> je donne les droits à un script -rwsr-x---   (ce script créé un fichier)
> je switch vers un autre utilisateur du groupe, je lance le script et il 
> créé le fichier avec owner ce dernier utilisateur pourquoi?
> 
> ---------
> This message was send by Majordomo 1.94.3. Please repport problems to
> manu@rtfm.be. If you want to be deleted from the list, send a mail to
> majordomo@rtfm.be with "unsubscribe linux-team" in the body.
> 

---------
This message was send by Majordomo 1.94.3. Please repport problems to
manu@rtfm.be. If you want to be deleted from the list, send a mail to
majordomo@rtfm.be with "unsubscribe linux-team" in the body.