Fossil

Check-in [77a72fb964]
Login

Check-in [77a72fb964]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Continuing work on the /aux page. Now working for static content.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | sub-cgi
Files: files | file ages | folders
SHA3-256: 77a72fb96402f4062f8a5366e5fa3f5323af4a01870bf1eefc7c3c631107c228
User & Date: drh 2019-07-24 10:54:59.933
Context
2019-07-24
10:54
Continuing work on the /aux page. Now working for static content. ... (Closed-Leaf check-in: 77a72fb964 user: drh tags: sub-cgi)
2019-07-23
23:25
Initial but incomplete work on an experimental /aux page that runs secondary CGI that has access to the Fossil user login credentials and similar information. This is an incremental check-in of work-in-progress. ... (check-in: 72f8e77612 user: drh tags: sub-cgi)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/auxwww.c.
76
77
78
79
80
81
82




83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

107
108
109
110
111
112
113
114

115
116
117
118
119
120





121


122
123
124
125
126
127
128
  }
  if( file_isdir(g.zAuxRoot,ExtFILE)!=1 ){
    zFailReason = "auxroot is not a directory";
    goto aux_not_found;
  }
  zPath = mprintf("%s/%s", g.zAuxRoot, zName);
  nRoot = (int)strlen(g.zAuxRoot);




  for(i=nRoot+1; zPath[i]; i++){
    char c = zPath[i];
    if( (c=='.' || c=='-') && zPath[i-1]=='/' ){
      zFailReason = "path element begins with '.' or '-'";
      goto aux_not_found;
    }
    if( !fossil_isalnum(c) && c!='_' && c!='-' && c!='.' ){
      zFailReason = "illegal character in path";
      goto aux_not_found;
    }
    if( c=='/' ){
      int isDir, isFile;
      zPath[i] = 0;
      isDir = file_isdir(zPath, ExtFILE);
      isFile = isDir==2 ? file_isfile(zPath, ExtFILE) : 0;
      zPath[i] = c;
      if( isDir==0 ){
        zFailReason = "path does not match any file or script";
        goto aux_not_found;
      }
      if( isFile!=0 ){
        zScript = mprintf("%.*s", i, zPath);
        nScript = i;
        break;

      }
    }
  }
  if( nScript==0 ){
    zFailReason = "path does not match any file or script";
    goto aux_not_found;
  }
  if( !file_isexe(zScript, ExtFILE) ){

    /* File is not executable.  Must be a regular file.  In that case,
    ** disallow extra path elements */
    if( zPath[nScript]!=0 ){
      zFailReason = "extra path elements after filename";
      goto aux_not_found;
    }





  }


  login_check_credentials();

aux_not_found:
  fossil_free(zPath);
  cgi_set_status(404, "Not Found");
  @ %h(zFailReason)
  return;







>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>








>






>
>
>
>
>

>
>







76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  }
  if( file_isdir(g.zAuxRoot,ExtFILE)!=1 ){
    zFailReason = "auxroot is not a directory";
    goto aux_not_found;
  }
  zPath = mprintf("%s/%s", g.zAuxRoot, zName);
  nRoot = (int)strlen(g.zAuxRoot);
  if( file_isfile(zPath, ExtFILE) ){
    nScript = (int)strlen(zPath);
    zScript = zPath;
  }else{
    for(i=nRoot+1; zPath[i]; i++){
      char c = zPath[i];
      if( (c=='.' || c=='-') && zPath[i-1]=='/' ){
        zFailReason = "path element begins with '.' or '-'";
        goto aux_not_found;
      }
      if( !fossil_isalnum(c) && c!='_' && c!='-' && c!='.' ){
        zFailReason = "illegal character in path";
        goto aux_not_found;
      }
      if( c=='/' ){
        int isDir, isFile;
        zPath[i] = 0;
        isDir = file_isdir(zPath, ExtFILE);
        isFile = isDir==2 ? file_isfile(zPath, ExtFILE) : 0;
        zPath[i] = c;
        if( isDir==0 ){
          zFailReason = "path does not match any file or script";
          goto aux_not_found;
        }
        if( isFile!=0 ){
          zScript = mprintf("%.*s", i, zPath);
          nScript = i;
          break;
        }
      }
    }
  }
  if( nScript==0 ){
    zFailReason = "path does not match any file or script";
    goto aux_not_found;
  }
  if( !file_isexe(zScript, ExtFILE) ){
    const char *zMime;
    /* File is not executable.  Must be a regular file.  In that case,
    ** disallow extra path elements */
    if( zPath[nScript]!=0 ){
      zFailReason = "extra path elements after filename";
      goto aux_not_found;
    }
    zMime = mimetype_from_name(zScript);
    if( zMime==0 ) zMime = "application/octet-stream";
    cgi_set_content_type(zMime);
    blob_read_from_file(cgi_output_blob(), zScript, ExtFILE);
    return;
  }
  /* If we reach this point, that means we are dealing with an executable
  ** file name zScript.  Run that file as CGI. */
  login_check_credentials();

aux_not_found:
  fossil_free(zPath);
  cgi_set_status(404, "Not Found");
  @ %h(zFailReason)
  return;
Changes to src/main.c.
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
  skin_override();
  zNotFound = find_option("notfound", 0, 1);
  noJail = find_option("nojail",0,0)!=0;
  allowRepoList = find_option("repolist",0,0)!=0;
  g.useLocalauth = find_option("localauth", 0, 0)!=0;
  g.sslNotAvailable = find_option("nossl", 0, 0)!=0;
  g.fNoHttpCompress = find_option("nocompress",0,0)!=0;
  g.zAuxRoot = find_option("auxroot",0,0);
  zInFile = find_option("in",0,1);
  if( zInFile ){
    backoffice_disable();
    g.httpIn = fossil_fopen(zInFile, "rb");
    if( g.httpIn==0 ) fossil_fatal("cannot open \"%s\" for reading", zInFile);
  }else{
    g.httpIn = stdin;







|







2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
  skin_override();
  zNotFound = find_option("notfound", 0, 1);
  noJail = find_option("nojail",0,0)!=0;
  allowRepoList = find_option("repolist",0,0)!=0;
  g.useLocalauth = find_option("localauth", 0, 0)!=0;
  g.sslNotAvailable = find_option("nossl", 0, 0)!=0;
  g.fNoHttpCompress = find_option("nocompress",0,0)!=0;
  g.zAuxRoot = find_option("auxroot",0,1);
  zInFile = find_option("in",0,1);
  if( zInFile ){
    backoffice_disable();
    g.httpIn = fossil_fopen(zInFile, "rb");
    if( g.httpIn==0 ) fossil_fatal("cannot open \"%s\" for reading", zInFile);
  }else{
    g.httpIn = stdin;
2395
2396
2397
2398
2399
2400
2401

2402
2403
2404
2405
2406
2407
2408
  const char *zIpAddr;    /* IP address of remote client */

  Th_InitTraceLog();
  login_set_capabilities("sx", 0);
  g.useLocalauth = 1;
  g.httpIn = stdin;
  g.httpOut = stdout;

  find_server_repository(2, 0);
  g.cgiOutput = 1;
  g.fNoHttpCompress = 1;
  g.fullHttpReply = 1;
  zIpAddr = cgi_ssh_remote_addr(0);
  if( zIpAddr && zIpAddr[0] ){
    g.fSshClient |= CGI_SSH_CLIENT;







>







2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
  const char *zIpAddr;    /* IP address of remote client */

  Th_InitTraceLog();
  login_set_capabilities("sx", 0);
  g.useLocalauth = 1;
  g.httpIn = stdin;
  g.httpOut = stdout;
  g.zAuxRoot = find_option("auxroot",0,1);
  find_server_repository(2, 0);
  g.cgiOutput = 1;
  g.fNoHttpCompress = 1;
  g.fullHttpReply = 1;
  zIpAddr = cgi_ssh_remote_addr(0);
  if( zIpAddr && zIpAddr[0] ){
    g.fSshClient |= CGI_SSH_CLIENT;
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
  const char *zStopperFile;    /* Name of file used to terminate server */
  zStopperFile = find_option("stopper", 0, 1);
#endif

  if( g.zErrlog==0 ){
    g.zErrlog = "-";
  }
  g.zAuxRoot = find_option("auxroot",0,0);
  zFileGlob = find_option("files-urlenc",0,1);
  if( zFileGlob ){
    char *z = mprintf("%s", zFileGlob);
    dehttpize(z);
    zFileGlob = z;
  }else{
    zFileGlob = find_option("files",0,1);







|







2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
  const char *zStopperFile;    /* Name of file used to terminate server */
  zStopperFile = find_option("stopper", 0, 1);
#endif

  if( g.zErrlog==0 ){
    g.zErrlog = "-";
  }
  g.zAuxRoot = find_option("auxroot",0,1);
  zFileGlob = find_option("files-urlenc",0,1);
  if( zFileGlob ){
    char *z = mprintf("%s", zFileGlob);
    dehttpize(z);
    zFileGlob = z;
  }else{
    zFileGlob = find_option("files",0,1);