-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing cgi with authentication check
- Loading branch information
1 parent
592c359
commit a45863f
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#define _GNU_SOURCE | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <strings.h> | ||
|
||
int IsUserLogin(char *user, int bufsize) | ||
{ | ||
FILE *fp = NULL; | ||
char buf[1024]; | ||
int login = 0; | ||
|
||
bzero(user, bufsize); | ||
fp = popen("/usr/syno/synoman/webman/modules/authenticate.cgi", "r"); | ||
if (!fp) { | ||
return 0; | ||
} | ||
|
||
bzero(buf, sizeof(buf)); | ||
fread(buf, 1024, 1, fp); | ||
|
||
if (strlen(buf) > 0) { | ||
snprintf(user, bufsize, "%s", buf); | ||
login = 1; | ||
} | ||
pclose(fp); | ||
|
||
return login; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
char user[256]; | ||
printf("Content-Type: text/html\r\n\r\n"); | ||
|
||
if (IsUserLogin(user, sizeof(user)) == 1) { | ||
printf("User is authenticated. Name: %s\n", user); } | ||
else { | ||
printf("User is not authenticated.\n"); | ||
} | ||
|
||
return 0; | ||
} | ||
|