Begin work on authentication
authorChip Black <bytex64@bytex64.net>
Tue, 21 Dec 2010 07:37:42 +0000 (01:37 -0600)
committerChip Black <bytex64@bytex64.net>
Tue, 21 Dec 2010 07:51:19 +0000 (01:51 -0600)
http_blerg.c

index 8abebaa..8543fb8 100644 (file)
@@ -96,6 +96,51 @@ ahc_derp (void *cls, struct MHD_Connection *connection, const char *url, const c
                        }
                }
        } else if (strncmp(url, "/put", 4) == 0) {
+               char *username;
+               const char *password = "testpass";
+               const char *realm = "Blerg Post";
+
+#define OPAQUE "d29fb6db8f21a6e99903651a9f87470e"
+#define DENIED "DENIED, MOTHERFUCKER"
+#define PAGE "DERP DERP AUTHENTICATED DERP"
+
+               if (*ptr == NULL) {
+                       *ptr = (void *) 1;
+
+                       username = MHD_digest_auth_get_username(connection);
+                       if (username == NULL) {
+                               response = MHD_create_response_from_data(strlen (DENIED), DENIED, MHD_NO, MHD_NO);  
+                               ret = MHD_queue_auth_fail_response(connection, realm, OPAQUE, response, MHD_NO);    
+                               MHD_destroy_response(response);  
+                               return ret;
+                       }
+
+                       printf("username: %s\n", username);
+
+                       ret = MHD_digest_auth_check(connection, realm, username, password, 300);
+                       free(username);
+
+                       if (ret == MHD_INVALID_NONCE || ret == MHD_NO) {
+                               response = MHD_create_response_from_data(strlen (DENIED), DENIED, MHD_NO, MHD_NO);  
+                               ret = MHD_queue_auth_fail_response(connection, realm, OPAQUE, response,
+                                                                  (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);       
+                               MHD_destroy_response(response);  
+                               return ret;
+                       }
+               }
+
+               *ptr = NULL;
+
+               if (url[4] != '/')
+                       return respond_404(connection);
+               ret = parse_url_info(url + 5, author, &record);
+               if ((ret & URL_INFO_AUTHOR) == 0)
+                       return respond_404(connection);
+
+               response = MHD_create_response_from_data(strlen(PAGE), PAGE, MHD_NO, MHD_NO);
+               ret = MHD_queue_response(connection, MHD_HTTP_OK, response);  
+               MHD_destroy_response(response);
+               return ret;
        } else {
                return respond_404(connection);
        }