瀏覽代碼

Using local var in open_auth_file

Sergey Lyubka 12 年之前
父節點
當前提交
d72645bf91
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      mongoose.c

+ 4 - 1
mongoose.c

@@ -2257,13 +2257,16 @@ static void open_auth_file(struct mg_connection *conn, const char *path,
                            struct file *filep) {
                            struct file *filep) {
   char name[PATH_MAX];
   char name[PATH_MAX];
   const char *p, *e, *gpass = conn->ctx->config[GLOBAL_PASSWORDS_FILE];
   const char *p, *e, *gpass = conn->ctx->config[GLOBAL_PASSWORDS_FILE];
+  struct file file = STRUCT_FILE_INITIALIZER;
 
 
   if (gpass != NULL) {
   if (gpass != NULL) {
     // Use global passwords file
     // Use global passwords file
     if (!mg_fopen(conn, gpass, "r", filep)) {
     if (!mg_fopen(conn, gpass, "r", filep)) {
       cry(conn, "fopen(%s): %s", gpass, strerror(ERRNO));
       cry(conn, "fopen(%s): %s", gpass, strerror(ERRNO));
     }
     }
-  } else if (mg_stat(conn, path, filep) && filep->is_directory) {
+    // Important: using local struct file to test path for is_directory flag.
+    // If filep is used, mg_stat() makes it appear as if auth file was opened.
+  } else if (mg_stat(conn, path, &file) && file.is_directory) {
     mg_snprintf(conn, name, sizeof(name), "%s%c%s",
     mg_snprintf(conn, name, sizeof(name), "%s%c%s",
                 path, '/', PASSWORDS_FILE_NAME);
                 path, '/', PASSWORDS_FILE_NAME);
     mg_fopen(conn, name, "r", filep);
     mg_fopen(conn, name, "r", filep);