1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
/*
* Exemple Primitive de recouvrement
* des primitives execve
* File: source.c
* Version: 0.0.1 Bêta GPLV3.
* Created by SAMBIA39 on 06/01/2015.
* Copyright (c) 2015 SAMBIA39 & Developpez.net
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define MAX_ARG 5 /* Nombre max des arguments */
/*
* Programme principal
*/
int main( int argc, char **argv ){
unsigned short i = 0;
char *ptr_new_arg[MAX_ARG] = { NULL };
if( (1) < argc ){
//Copie des arguments
ptr_new_arg[0] = argv[1];
for( i = 1; argc != i; i++ )
ptr_new_arg[i] = argv[i];
/*
* Affichage d'informations
* complémentaires
*/
fprintf( stdout, "Lancement de %s ...\n", argv[1] );
fprintf( stdout, "PID = %d && PPID = %d [%d]\n",
getpid(), getppid(), getuid() );
/*
* Gestion d'erreur
* en cas d'échec de la primitive
*/
errno = 0;
if( (-1) == execve( argv[1], ptr_new_arg, NULL ) ){
fprintf(stderr, "(%d)\t:%s\n\t:%s\n", errno,
"Aucun fichier exécutable/Error\n", strerror(errno) );
_exit( EXIT_FAILURE );
}
}else{
fprintf( stderr, "Attention/Échec -> argument inssufisant\n");
_exit( EXIT_FAILURE );
}
return EXIT_FAILURE;
} |
Partager