Skip to content
Snippets Groups Projects
Commit 74b92cc8 authored by deuce's avatar deuce
Browse files

Support authentication and the new SERVICE_STATUS

parent c0f0636d
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include "sbbs_status.h"
#include "dirwrap.h"
#include "genwrap.h"
void usage(void) {
printf("Usage: showstat <path>\n");
}
static struct termios old;
void noecho(void)
{
struct termios new = old;
new.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &new);
}
void restore(void)
{
tcsetattr(STDIN_FILENO, TCSANOW, &old);
}
int main(int argc, char **argv)
{
SOCKET sock;
......@@ -17,6 +33,7 @@ int main(int argc, char **argv)
char buf[4096];
struct sbbs_status_msg *msg;
time_t t;
char *p;
if (argc != 2) {
usage();
......@@ -27,6 +44,7 @@ int main(int argc, char **argv)
return 1;
}
tcgetattr(STDIN_FILENO, &old);
sock = socket(PF_UNIX, SOCK_SEQPACKET, 0);
if (sock == INVALID_SOCKET)
return 1;
......@@ -38,12 +56,31 @@ int main(int argc, char **argv)
#else
addrlen = offsetof(struct sockaddr_un, un_addr.sun_path) + strlen(addr.sun_path) + 1;
#endif
printf("UN: ");
fgets(buf, sizeof(buf), stdin);
truncnl(buf);
noecho();
p = strchr(buf, 0);
p++;
printf("PW: ");
fgets(p, sizeof(buf)-(p-buf), stdin);
truncnl(p);
p = strchr(p, 0);
p++;
printf("\nSY: ");
fgets(p, sizeof(buf)-(p-buf), stdin);
truncnl(p);
p = strchr(p, 0);
p++;
restore();
puts("");
if (connect(sock, (void *)&addr, addrlen) != 0) {
fprintf(stderr, "Unable to connect!\n");
return 1;
}
send(sock, buf, 1, 0);
send(sock, buf, p-buf, 0);
while (sock != -1) {
if (recv(sock, buf, sizeof(buf), 0) <= 0) {
close(sock);
......@@ -70,6 +107,12 @@ int main(int argc, char **argv)
case SERVICE_WEB:
printf("WEB: ");
break;
case SERVICE_STATUS:
printf("STATUS: ");
break;
default:
printf("UNKNOWN SERVICE %" PRIu32 " ", msg->hdr.service);
break;
}
switch(msg->hdr.type) {
case STATUS_CLIENTS:
......@@ -125,7 +168,7 @@ int main(int argc, char **argv)
printf("thread %s (%d)\n", msg->msg.thread_up.up ? "up" : "down", msg->msg.thread_up.setuid);
break;
default:
printf("!Unhandled type: %d\b", msg->hdr.type);
printf("!Unhandled type: %" PRIu32 "\n", msg->hdr.type);
break;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment