added a wait mode to make ncurses possible
This commit is contained in:
parent
7058a7e6c1
commit
bd966ba2e6
|
@ -0,0 +1,48 @@
|
||||||
|
# vim: set syntax=yaml :
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignEscapedNewlinesLeft: false
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: false
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: false
|
||||||
|
BinPackParameters: false
|
||||||
|
BreakBeforeBinaryOperators: true
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeTernaryOperators: false
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
ColumnLimit: 120
|
||||||
|
CommentPragmas: ''
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 0
|
||||||
|
ContinuationIndentWidth: 0
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
DerivePointerBinding: false
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentFunctionDeclarationAfterType: false
|
||||||
|
IndentWidth: 4
|
||||||
|
Language: Cpp
|
||||||
|
MaxEmptyLinesToKeep: 2
|
||||||
|
NamespaceIndentation: All
|
||||||
|
ObjCSpaceAfterProperty: true
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 100
|
||||||
|
PenaltyBreakComment: 100
|
||||||
|
PenaltyBreakFirstLessLess: 0
|
||||||
|
PenaltyBreakString: 100
|
||||||
|
PenaltyExcessCharacter: 1
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 20
|
||||||
|
PointerBindsToType: false
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
Standard: Auto
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
|
@ -51,5 +51,5 @@ Module.symvers
|
||||||
Mkfile.old
|
Mkfile.old
|
||||||
dkms.conf
|
dkms.conf
|
||||||
|
|
||||||
|
tags
|
||||||
rsudo
|
rsudo
|
||||||
|
|
17
Makefile
17
Makefile
|
@ -1,3 +1,16 @@
|
||||||
|
INSTALL_PREFIX = /usr/local/bin
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
all:
|
all: rsudo setuid
|
||||||
gcc -o ./rsudo rsudo.c
|
|
||||||
|
setuid: rsudo
|
||||||
|
chown root:root rsudo
|
||||||
|
chmod 4711 rsudo
|
||||||
|
|
||||||
|
.PHONY: all setuid
|
||||||
|
|
||||||
|
rsudo: rsudo.c
|
||||||
|
$(CC) -o ./rsudo rsudo.c
|
||||||
|
|
||||||
|
install: rsudo
|
||||||
|
install -Dm4711 rsudo $(INSTALL_PREFIX)/rsudo
|
||||||
|
|
211
rsudo.c
211
rsudo.c
|
@ -11,28 +11,39 @@
|
||||||
Copyright (C) Luna Mendes 2017
|
Copyright (C) Luna Mendes 2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/socket.h>
|
#include <stdlib.h>
|
||||||
#include <sys/un.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
const char* sock_path = "/home/luna/local.git/memed/memed.succ";
|
// lol C bool lib
|
||||||
|
typedef int bool;
|
||||||
|
enum { false, true };
|
||||||
|
|
||||||
|
const char *sock_path = "/var/sock/memed.sock";
|
||||||
|
|
||||||
|
struct args_context {
|
||||||
|
int positional_count;
|
||||||
|
char **positional;
|
||||||
|
bool nowait;
|
||||||
|
};
|
||||||
|
|
||||||
struct header_s {
|
struct header_s {
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
int op;
|
int op;
|
||||||
};
|
};
|
||||||
|
|
||||||
char *join(const char* s1, const char* s2)
|
char *join(const char *s1, const char *s2) {
|
||||||
{
|
free((void *)s1);
|
||||||
char* result = malloc(strlen(s1) + strlen(s2) + 1);
|
char *result = malloc(strlen(s1) + strlen(s2) + 1);
|
||||||
|
if (result) {
|
||||||
if (result)
|
|
||||||
{
|
|
||||||
strcpy(result, s1);
|
strcpy(result, s1);
|
||||||
strcat(result, s2);
|
strcat(result, s2);
|
||||||
}
|
}
|
||||||
|
@ -40,8 +51,19 @@ char *join(const char* s1, const char* s2)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
void print_help() {
|
||||||
{
|
printf("sudo thing that integrates (badly) with discord\n\n"
|
||||||
|
"made by: luba and arsen\n\n"
|
||||||
|
"Usage: <--nowait> [command ...]\n"
|
||||||
|
" --nowait - Schedule command for execution by memed\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
if (argc == 1) {
|
||||||
|
print_help();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
// the idea here is to open the socket
|
// the idea here is to open the socket
|
||||||
// send a message to it and run asap
|
// send a message to it and run asap
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
|
@ -54,8 +76,7 @@ int main(int argc, char **argv)
|
||||||
// rc read count
|
// rc read count
|
||||||
int fd, rc;
|
int fd, rc;
|
||||||
|
|
||||||
if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
|
||||||
{
|
|
||||||
perror("socket error");
|
perror("socket error");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
@ -63,96 +84,102 @@ int main(int argc, char **argv)
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
|
|
||||||
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path)-1);
|
strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1);
|
||||||
|
|
||||||
LOG_INFO("main", "connecting");
|
LOG_INFO("main", "connecting");
|
||||||
if ( connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1 )
|
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
|
||||||
{
|
|
||||||
perror("connect error");
|
perror("connect error");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the hello
|
// read the hello
|
||||||
// We start by reading and filling our header
|
// We start by reading and filling our header
|
||||||
if ((rc = recv(fd, &header, 8, 0)) < 0)
|
if ((rc = recv(fd, &header, 8, 0)) < 0) {
|
||||||
{
|
|
||||||
perror("recv");
|
perror("recv");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%d %d\n", header.len, header.op);
|
if (strcmp(argv[1], "--nowait") == 0) {
|
||||||
|
argv++; // luba pls no use argv[0] becus its --nowait now
|
||||||
|
printf("%d %d\n", header.len, header.op);
|
||||||
|
|
||||||
// Then we proceed to, with the data from header,
|
// Then we proceed to, with the data from header,
|
||||||
// read the message
|
// read the message
|
||||||
if ((rc = recv(fd, &buffer, header.len, 0)) < 0)
|
if ((rc = recv(fd, &buffer, header.len, 0)) < 0) {
|
||||||
{
|
perror("recv");
|
||||||
perror("recv");
|
exit(-1);
|
||||||
exit(-1);
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
if(strlen(buffer) != header.len || strlen(buffer) - 1 != header.len)
|
||||||
|
{
|
||||||
|
printf("%u %d\n", strlen(buffer), header.len);
|
||||||
|
LOG_ERROR("main", "hello length != header length");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (header.op != 0) {
|
||||||
|
LOG_ERROR("main", "incorrect header op");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO("main", "finished hello");
|
||||||
|
|
||||||
|
char *tot = "";
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
char *arg = argv[i];
|
||||||
|
tot = join(tot, arg);
|
||||||
|
|
||||||
|
if (i != argc - 1) tot = join(tot, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert uid to string
|
||||||
|
int uid = getuid();
|
||||||
|
char uid_str[6];
|
||||||
|
|
||||||
|
sprintf(uid_str, "%d", uid);
|
||||||
|
|
||||||
|
tot = join(tot, ",");
|
||||||
|
tot = join(tot, uid_str);
|
||||||
|
|
||||||
|
tot = join(tot, ",");
|
||||||
|
tot = join(tot, getenv("USER"));
|
||||||
|
|
||||||
|
printf("sending command: %s\n", tot);
|
||||||
|
|
||||||
|
// encode our data
|
||||||
|
struct header_s send_h;
|
||||||
|
send_h.len = strlen(tot);
|
||||||
|
send_h.op = 2;
|
||||||
|
|
||||||
|
if (send(fd, &send_h, sizeof(send_h), 0) < 0) {
|
||||||
|
perror("send req");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (send(fd, tot, strlen(tot), 0) < 0) {
|
||||||
|
perror("send req total");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
shutdown(fd, SHUT_RDWR);
|
||||||
|
|
||||||
|
printf("Successfully communicated your command to memed!\n");
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
exit(0);
|
||||||
|
} else {
|
||||||
|
// TODO luna make thje check
|
||||||
|
setuid(0);
|
||||||
|
setenv("USER", "root", true);
|
||||||
|
setenv("HOME", "/root", true); // todo: dont care
|
||||||
|
int err = execvp(argv[1], argv + 1);
|
||||||
|
if (err == -1)
|
||||||
|
perror("rsudo: exec");
|
||||||
|
else
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
if(strlen(buffer) != header.len || strlen(buffer) - 1 != header.len)
|
|
||||||
{
|
|
||||||
printf("%u %d\n", strlen(buffer), header.len);
|
|
||||||
LOG_ERROR("main", "hello length != header length");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(header.op != 0)
|
|
||||||
{
|
|
||||||
LOG_ERROR("main", "incorrect header op");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_INFO("main", "finished hello");
|
|
||||||
|
|
||||||
char *tot = "";
|
|
||||||
for(int i = 1; i < argc; i++)
|
|
||||||
{
|
|
||||||
char *arg = argv[i];
|
|
||||||
tot = join(tot, arg);
|
|
||||||
|
|
||||||
if(i != argc - 1) tot = join(tot, " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert uid to string
|
|
||||||
int uid = getuid();
|
|
||||||
char uid_str[6];
|
|
||||||
|
|
||||||
sprintf(uid_str, "%d", uid);
|
|
||||||
|
|
||||||
tot = join(tot, ",");
|
|
||||||
tot = join(tot, uid_str);
|
|
||||||
|
|
||||||
tot = join(tot, ",");
|
|
||||||
tot = join(tot, getenv("USER"));
|
|
||||||
|
|
||||||
printf("sending command: %s\n", tot);
|
|
||||||
|
|
||||||
// encode our data
|
|
||||||
struct header_s send_h;
|
|
||||||
send_h.len = strlen(tot);
|
|
||||||
send_h.op = 2;
|
|
||||||
|
|
||||||
if (send(fd, &send_h, sizeof(send_h), 0) < 0)
|
|
||||||
{
|
|
||||||
perror("send req");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (send(fd, tot, strlen(tot), 0) < 0)
|
|
||||||
{
|
|
||||||
perror("send req total");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
shutdown(fd, SHUT_RDWR);
|
|
||||||
|
|
||||||
printf("Successfully communicated your command to memed!\n");
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue