Προς το περιεχόμενο

C-linux


milva coath

Προτεινόμενες αναρτήσεις

Δημοσ.

Kalhspera kai xronia polla:)

 

exw to ekshs provlhma:exw grapsei ena programma se c k 8elw mesw linux na kalw thn sunarthsh "ls".auto 8a ginei me thn sunarthsh exec alla den gnwrizw poia exec na xrhsimopoihsw..m endiaferei aplws h ls(xwris orismata).dokimasa thn execvp("ls",NULL) alla den leitourgei..an kserei kapoios as voh8hsei..:)

 

Euxaristw!

Δημοσ.

execv.c

---------

>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
 char *exec_argv[] = { NULL };
 int ret;

 ret = execv("/bin/ls", exec_argv);

 if (ret == -1)
   fprintf(stderr, "execv() error\n");

 return 0;
}

 

gcc -Wall -W -O2 execv.c -o execv

./execv

 

8a prepei to prwto argument ths execv na einai to fullpath tou binary

 

# man exec (gia perissoteres plhrofories)

 

PS. H system den einai toso secure oso h execv epeidi diabazei to $PATH

 

Apo to man:

 

Do not use system() from a program with set-user-ID or set-group-ID privileges, because strange values for some environment vari-ables might be used to subvert system integrity. Use the exec(3) family of functions instead, but not execlp(3) or execvp(3). system() will not, in fact, work properly from programs with set-user-ID or set-group-ID privileges on systems on which /bin/sh is bash version 2, since bash 2 drops privileges on startup. (Debian uses a modified bash which does not do this when invoked as sh.)

Δημοσ.

euxaristw poly kai tous 2!h alh8eia einai oti vrhka ena paradeigma apo to opensource pou leei ta idia me auta pou leei kai o diavol opote akolou8hsa ton tropo tou k epaikse.twra epeidh einai TCP k 8elw auta pou emfanizei ston server na ta emfanizei sto console tou client mallon prepei na kanw xrhsh enos buffer k meta write alla elpizw na ta kataferw!:)

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...