C: check-root-user.c
This commit is contained in:
parent
60ba2c59e7
commit
bbed68cff2
5
code/C/.clang-format
Normal file
5
code/C/.clang-format
Normal file
@ -0,0 +1,5 @@
|
||||
Language: Cpp
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 2
|
||||
ColumnLimit: 132
|
||||
SortIncludes: Never
|
18
code/C/System/check-root-user.c
Normal file
18
code/C/System/check-root-user.c
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* https://man.openbsd.org/getuid
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void main(int argc, char const *argv[]) {
|
||||
uid_t user = getuid();
|
||||
uid_t privs = geteuid();
|
||||
printf("User: %u\n", user);
|
||||
printf("Privs: %u\n", privs);
|
||||
|
||||
puts("::");
|
||||
|
||||
char *login = getlogin();
|
||||
printf("%s\n", login);
|
||||
}
|
@ -3,10 +3,8 @@ atomic_bool running = true;
|
||||
#define PORT 8000
|
||||
#define PREFIX "/api"
|
||||
|
||||
int callback_default(const struct _u_request *request,
|
||||
struct _u_response *response, void *user_data);
|
||||
int callback_all_test_foo(const struct _u_request *request,
|
||||
struct _u_response *response, void *user_data);
|
||||
int callback_default(const struct _u_request *request, struct _u_response *response, void *user_data);
|
||||
int callback_all_test_foo(const struct _u_request *request, struct _u_response *response, void *user_data);
|
||||
|
||||
void *thread_server(void *vargp) {
|
||||
int ret;
|
||||
@ -18,10 +16,8 @@ void *thread_server(void *vargp) {
|
||||
|
||||
instance.max_post_body_size = 1024;
|
||||
|
||||
ulfius_add_endpoint_by_val(&instance, "GET", PREFIX, "/param/:name", 0,
|
||||
&callback_all_test_foo, "user data 1");
|
||||
ulfius_add_endpoint_by_val(&instance, "POST", PREFIX, "/param/:name", 0,
|
||||
&callback_all_test_foo, "user data 2");
|
||||
ulfius_add_endpoint_by_val(&instance, "GET", PREFIX, "/param/:name", 0, &callback_all_test_foo, "user data 1");
|
||||
ulfius_add_endpoint_by_val(&instance, "POST", PREFIX, "/param/:name", 0, &callback_all_test_foo, "user data 2");
|
||||
|
||||
ulfius_set_default_endpoint(&instance, &callback_default, NULL);
|
||||
|
||||
@ -41,18 +37,15 @@ void *thread_server(void *vargp) {
|
||||
ulfius_clean_instance(&instance);
|
||||
}
|
||||
|
||||
int callback_default(const struct _u_request *request,
|
||||
struct _u_response *response, void *user_data) {
|
||||
int callback_default(const struct _u_request *request, struct _u_response *response, void *user_data) {
|
||||
(void)(request);
|
||||
(void)(user_data);
|
||||
ulfius_set_string_body_response(response, 404,
|
||||
"Page not found, do what you want");
|
||||
ulfius_set_string_body_response(response, 404, "Page not found, do what you want");
|
||||
|
||||
return U_CALLBACK_CONTINUE;
|
||||
}
|
||||
|
||||
int callback_all_test_foo(const struct _u_request *request,
|
||||
struct _u_response *response, void *user_data) {
|
||||
int callback_all_test_foo(const struct _u_request *request, struct _u_response *response, void *user_data) {
|
||||
// url_params = request->map_url
|
||||
// post_params = request->map_post_body
|
||||
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
#include "webui.h"
|
||||
|
||||
void my_function_string(webui_event_t* e) {
|
||||
void my_function_string(webui_event_t *e) {
|
||||
|
||||
// JavaScript:
|
||||
// webui_fn('MyID_One', 'Hello');
|
||||
|
||||
const char* str = webui_get_string(e);
|
||||
const char *str = webui_get_string(e);
|
||||
printf("my_function_string: %s\n", str); // Hello
|
||||
|
||||
// Need Multiple Arguments?
|
||||
@ -21,7 +21,7 @@ void my_function_string(webui_event_t* e) {
|
||||
// bar = my_json[1];
|
||||
}
|
||||
|
||||
void my_function_integer(webui_event_t* e) {
|
||||
void my_function_integer(webui_event_t *e) {
|
||||
|
||||
// JavaScript:
|
||||
// webui_fn('MyID_Two', 123456789);
|
||||
@ -30,19 +30,19 @@ void my_function_integer(webui_event_t* e) {
|
||||
printf("my_function_integer: %lld\n", number); // 123456789
|
||||
}
|
||||
|
||||
void my_function_boolean(webui_event_t* e) {
|
||||
void my_function_boolean(webui_event_t *e) {
|
||||
|
||||
// JavaScript:
|
||||
// webui_fn('MyID_Three', true);
|
||||
|
||||
bool status = webui_get_bool(e); // True
|
||||
if(status)
|
||||
if (status)
|
||||
printf("my_function_boolean: True\n");
|
||||
else
|
||||
printf("my_function_boolean: False\n");
|
||||
}
|
||||
|
||||
void my_function_with_response(webui_event_t* e) {
|
||||
void my_function_with_response(webui_event_t *e) {
|
||||
|
||||
// JavaScript:
|
||||
// const result = webui_fn('MyID_Four', number);
|
||||
@ -58,8 +58,7 @@ void my_function_with_response(webui_event_t* e) {
|
||||
int main() {
|
||||
|
||||
// HTML
|
||||
const char* my_html =
|
||||
"<html>"
|
||||
const char *my_html = "<html>"
|
||||
" <head>"
|
||||
" <title>Call C from JavaScript Example</title>"
|
||||
" <style>"
|
||||
@ -123,7 +122,5 @@ int main() {
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow) {
|
||||
return main();
|
||||
}
|
||||
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow) { return main(); }
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user