How to make directories for an specific user using C, CGI, HTML? -


and have issue, im creating directories using c, cgi , html, started 2 source codes, 1 this:

/*  * newdir.c - create directory  */ #include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <stdio.h>  int main(int argc, char *argv[]) {      printf("\n#argumentos: %d\n", argc);      if(mkdir(argv[1], 0777)) {       perror("mkdir");       exit(exit_failure);      }      exit(exit_success); } 

and have other one:

#include <stdio.h> #include <stdlib.h> #include <string.h>  // here same sampleprogram.c except  // there differences when have read in string int main(void) {   char *data;   char* s = malloc(100 * sizeof(char));   printf("%s%c%c\n",      "content-type:text/html;charset=iso-8859-1",13,10);    int length = atoi(getenv("content_length"));   int j =0;   char c;   c = getchar();   data = malloc(sizeof(char) * (length + 1) );    while ( c != eof && j < length ) {     //read in 1 character     data[j] = c;     c = getchar();     j++;    }   data[j] = '\0';    printf("<title>make directorys</title>");   printf("<h3> make new directory \n <br> %s ");   if(data == null) {     printf("<p>error! error in passing data form script.");     return 0;   }    char delimiters[] = "&";    char* str = strtok( data, delimiters);       sscanf(str, "s=%s", s);      int i;      (i=0; < strlen(s); i++ ) {        if (s[i] == '+')      s[i] = ' ';       }       str = strtok(null, delimiters);      //s name collected text area in html file      if(mkdir(s, 0777)) {       perror("mkdir");       exit(exit_failure);      }      exit(exit_success);    return 0; } 

so did add first code second other, other code collects information text field of html , processed cgi script. works perfect , directory created user " daemon " , can not add inside if not set permissions 777 again console, why happens ? wrong? pd: if run first code console works perfect, i'm user :(

you have no way solve this, because user executes scripts/programs daemon user. it's way setup web server, web server run daemon user, , means every script/program invoked web server run same user too.

also, both programs posted poorly coded, , doesn't seem need write them in language.

#include <stdio.h> #include <stdlib.h> #include <string.h>  int main(void) {     const char *content_length;     char *data;     char s[100];      content_length = getenv("content_length");     if (content_length != null)     {         int length;         int j;         char c;          printf("content-type: text/html;charset=iso-8859-1\r\n\n");          length = atoi(content_length);         c = getchar();         data = malloc(length + 1);         if (data != null)         {             const char *delimiters;             char *token;              delimiters = "&";             while ((c != eof) && (j < length))             {                 data[j] = c;                 c = getchar();                 j++;             }             data[j] = '\0';              printf("<title>make directorys</title>");             printf("<h3> make new directory \n <br> %s ");              token = strtok(data, delimiters);             if ((token != null) && (sscanf(str, "s=%99s", s)  == 1))             {                 int i;                  (i = 0 ; s[i] != '\0' ; i++ )                 {                     if (s[i] == '+')                         s[i] = ' ';                 }                  if (mkdir(s, 0777))                 {                     perror("mkdir");                     exit(exit_failure);                 }             }             free(data);         }     }     return 0; } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -