Título: chmod aleatorio con program en c++
Publicado por: patilanz en 22 Junio 2015, 00:02 am
Hola escribí esto: #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <string.h> int main(){ char name[100]; int i = 0; int file = -1; do{ if(file != -1) close(file); sprintf(name,"file%d",i); }while((file = open(name,O_RDONLY)) != -1 && ++i); file = open(name,O_WRONLY | O_CREAT); char text[1024]; for(int j = 0;j<i+1;j++){ sprintf(text,"Hola %d veces\n",j); while(write(file,text,strlen(text)) != strlen(text)); } close(file); return 0; }
luego use un bucle while true; do ./a.out;done
En el escritorio me aparecieron mucho archivos con sus permisos aleatorios y raros. Ejemplo: ----r-Sr-t 1 root root 14155 jun 21 23:57 file950 --wS---r-x 1 root root 14170 jun 21 23:57 file951 ---Sr-Sr-x 1 root root 14185 jun 21 23:57 file952 ------Sr-x 1 root root 14200 jun 21 23:57 file953 --ws---r-t 1 root root 14215 jun 21 23:57 file954 -rwxr-Sr-x 1 root root 14230 jun 21 23:57 file955 -r----Sr-x 1 root root 14245 jun 21 23:57 file956 -r-xr--r-t 1 root root 14260 jun 21 23:57 file957 -r-sr--r-t 1 root root 14275 jun 21 23:57 file958 -r-Sr-Sr-t 1 root root 14290 jun 21 23:57 file959 -r-Sr--r-T 1 root root 1348 jun 21 23:57 file96 --wSr--r-x 1 root root 14305 jun 21 23:57 file960 ---xr--r-x 1 root root 14320 jun 21 23:57 file961 -rwSr-Sr-t 1 root root 14335 jun 21 23:57 file962 --wxr-Sr-x 1 root root 14350 jun 21 23:57 file963 -r-sr--r-t 1 root root 14365 jun 21 23:57 file964 ---xr--r-t 1 root root 14380 jun 21 23:57 file965 -rw-r--r-x 1 root root 14395 jun 21 23:57 file966 -rw-r--r-t 1 root root 14410 jun 21 23:57 file967 -rwx--Sr-x 1 root root 14425 jun 21 23:57 file968 ---xr--r-x 1 root root 14440 jun 21 23:57 file969 -r--r-Sr-T 1 root root 1362 jun 21 23:57 file97 -r--r--r-x 1 root root 14455 jun 21 23:57 file970 --w----r-t 1 root root 14470 jun 21 23:57 file971 -r----Sr-t 1 root root 14485 jun 21 23:57 file972 -rw---Sr-x 1 root root 14500 jun 21 23:57 file973 ------Sr-x 1 root root 14515 jun 21 23:57 file974 --w-r-Sr-t 1 root root 14530 jun 21 23:57 file975 -rw---Sr-t 1 root root 14545 jun 21 23:57 file976 -rwx--Sr-t 1 root root 14560 jun 21 23:57 file977 ---x--Sr-t 1 root root 14575 jun 21 23:57 file978 -------r-t 1 root root 14590 jun 21 23:57 file979 ----r-Sr-T 1 root root 1376 jun 21 23:57 file98 -r-sr--r-t 1 root root 14605 jun 21 23:57 file980 -rwxr--r-t 1 root root 14620 jun 21 23:57 file981 --wxr-Sr-t 1 root root 14635 jun 21 23:57 file982 --ws---r-t 1 root root 14650 jun 21 23:57 file983 ---Sr--r-x 1 root root 14665 jun 21 23:57 file984 -rw-r--r-x 1 root root 14680 jun 21 23:57 file985 -rw-r-Sr-t 1 root root 14695 jun 21 23:57 file986 --wxr-Sr-t 1 root root 14710 jun 21 23:57 file987 -r-S--Sr-t 1 root root 14725 jun 21 23:58 file988 --wsr--r-x 1 root root 14740 jun 21 23:58 file989 --ws---r-T 1 root root 1390 jun 21 23:57 file99 --wS---r-t 1 root root 14755 jun 21 23:58 file990 -r-xr--r-x 1 root root 14770 jun 21 23:58 file991 -rwS--Sr-x 1 root root 14785 jun 21 23:58 file992
Porque?? Saludos
Título: Re: chmod aleatorio con program en c++
Publicado por: MinusFour en 22 Junio 2015, 00:47 am
Yo creo que esta pregunta iría mejor en C. Yo no puedo ver que hagas chmod pero bueno, no se mucho de C en todo caso: file = open(name,O_WRONLY | O_CREAT);
Esta creando tus archivos raros.
Título: Re: chmod aleatorio con program en c++
Publicado por: patilanz en 22 Junio 2015, 10:12 am
Si, esta parte me crea el archivo pero se produce lo mismos si hago un chmod con 0x00777 chmod(fileName,0x00777);
Aunque aqui el resultado es siempre -r-xrwSrwtQue significa ?? Porque nunca he visto una S mayúscula y la t no me cuadran. Y el open(..) debería de crear un archivo con los mismos permisos que el programa que lo esta ejecutando.
Título: Re: chmod aleatorio con program en c++
Publicado por: banwave_ en 22 Junio 2015, 18:49 pm
El chmod en C se usa sin "0x", prueba: chmod(fileName,00777);
Para el caso de tu programa, creo que al OPEN debes indicar cada permiso con RWX y asi tu umask te limita en la creacion del archivo, ejemplo: file = open(name,O_RDWR | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
Y si tu umask es 0022, entonces tus archivos se crearan con "-rwxr-xr-x"..
Título: Re: chmod aleatorio con program en c++
Publicado por: patilanz en 22 Junio 2015, 22:49 pm
Vale pero que significan los permisos que se crearon antes ? La S mayúscula. Es un archivo sin permisos?
Título: Re: chmod aleatorio con program en c++
Publicado por: banwave_ en 22 Junio 2015, 23:27 pm
La S mayuscula son permisos especiales: `s' If the setuid or setgid bit and the corresponding executable bit are both set.
`S' If the setuid or setgid bit is set but the corresponding executable bit is not set.
Te paso esta liga con un poco de info. http://rm-rf.es/permisos-especiales-setuid-setgid-sticky-bit/ http://www.linuxnix.com/2011/12/suid-set-suid-linuxunix.html Lo que aun no reviso es porque te asigno esos permisos random, apenas voy hacer debug de tu programa :xD
Título: Re: chmod aleatorio con program en c++
Publicado por: patilanz en 23 Junio 2015, 03:37 am
Gracias por los links Me los leí y probé esto: Tengo 1 shell y una carpeta -rwsrwxr-x 1 root root 25 jun 23 03:29 test.sh drwxr-xr-x 2 root root 4096 jun 23 03:28 a
Shell: #!/bin/sh id chmod 777 a
Ahora entro desde el usuario y abro la shell test.sh que contiene el SUID por lo que debería de tener los mismos permisos que el usuario creador. Pero no es asi...
Título: Re: chmod aleatorio con program en c++
Publicado por: banwave_ en 23 Junio 2015, 19:37 pm
Man.... no es por nada, pero tienes que buscar un poco antes de publicar las dudas, hay mucha info sobre estos temas: http://unix.stackexchange.com/questions/364/allow-setuid-on-shell-scripts
Mientras tanto, tu programa funciono? o al final que necesitas hacer?
|