This commit is contained in:
Your Name 2024-07-02 19:48:16 +00:00
parent 21be7fd279
commit 5a29ac490e
13 changed files with 51 additions and 50 deletions

6
TODO
View File

@ -16,8 +16,6 @@ sha*
md5 md5
Other: Other:
watch
ps
sysctl sysctl
ping ping
ncat ncat
@ -31,10 +29,10 @@ Other:
swapon swapon
swapoff swapoff
hexdump hexdump
sed
Loginutils: Loginutils:
userctl usersctl
groupctl
getty getty
Modutils: Modutils:

View File

@ -5,7 +5,7 @@
#define BUF_SIZE 1024 * 1024 #define BUF_SIZE 1024 * 1024
#ifdef _SHRED_C #ifdef _SHRED_C
/* Random source (shred) */ /* source of random (shred) */
#define RAND_SOURCE "/dev/urandom" #define RAND_SOURCE "/dev/urandom"
#endif #endif
@ -16,7 +16,7 @@
#ifdef _PW_CHECK_H #ifdef _PW_CHECK_H
/* Pw_check. Salt for crypt() */ /* Pw_check. Salt for crypt() */
char MU_SALT_ENC[] = {'s', 'a', 'l', 't'}; int MU_SALT_ENC[] = {'s', 'a', 'l', 't'};
char MU_SALT_BUF[sizeof(MU_SALT_ENC) + 1]; char MU_SALT_BUF[sizeof(MU_SALT_ENC) + 1];
#endif #endif

View File

@ -1,4 +1,6 @@
#!/bin/sh #!/bin/sh
#FIXME!!!
echo "[*] Umounting..." echo "[*] Umounting..."
umount -a umount -a

View File

@ -11,12 +11,11 @@
void dec_salt(void) { void dec_salt(void) {
size_t i; size_t i;
for (i = 0; i < sizeof(MU_SALT_ENC) / sizeof(int); i++) for (i = 0; i < sizeof(MU_SALT_ENC) / sizeof(int); i++)
MU_SALT_BUF[i] = MU_SALT_ENC[i]; MU_SALT_BUF[i] = (char)MU_SALT_ENC[i];
MU_SALT_BUF[i + 1] = '\0'; MU_SALT_BUF[i + 1] = '\0';
} }
/* Using not only there */
char *enc_password(const char *prog_name, const char *pass, const char *salt) { char *enc_password(const char *prog_name, const char *pass, const char *salt) {
if (salt == NULL) if (salt == NULL)
dec_salt(); dec_salt();

View File

@ -32,7 +32,7 @@ int main(int argc, char **argv) {
break; break;
default: default:
printf("bdname [sd] [str]\n\t-s SFX Set suffix\n\t-d Use dirname instead of basename\n"); puts("bdname [sd] [str]\n\t-s SFX Set suffix\n\t-d Use dirname instead of basename");
return 0; return 0;
} }
} }

View File

@ -33,7 +33,7 @@ int cat(const char *path) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int opt; int opt;
while ((opt = getopt(argc, argv, "")) != -1) { while ((opt = getopt(argc, argv, "")) != -1) {
printf("cat [file1 file2...]\n"); puts("cat [file1 file2...]");
return 0; return 0;
} }

View File

@ -56,7 +56,7 @@ int main(int argc, char **argv) {
break; break;
default: default:
printf("chgrp [RfHv] [group] [file1 file2...]\n\t-H Symbolic link\n\t-R Recursive\n\t-f Silent\n\t-v Verbose\n"); puts("chgrp [RfHv] [group] [file1 file2...]\n\t-H Symbolic link\n\t-R Recursive\n\t-f Silent\n\t-v Verbose");
return 0; return 0;
} }
} }

View File

@ -71,7 +71,7 @@ int main(int argc, char **argv) {
break; break;
default: default:
printf("chmod [RfHv] [ugoa]{+|-}[rwxXst] / [0 - 777] [file1 file2...]\n\t-H Symbolic link\n\t-R Recursive\n\t-f Silent\n\t-v Verbose\n"); puts("chmod [RfHv] [ugoa]{+|-}[rwxXst] / [0 - 777] [file1 file2...]\n\t-H Symbolic link\n\t-R Recursive\n\t-f Silent\n\t-v Verbose");
return 0; return 0;
} }
} }

View File

@ -6,7 +6,7 @@
int main(const int argc, char **argv) { int main(const int argc, char **argv) {
if (argc < 3 || !strcmp(argv[argc - 1], "--help")) { if (argc < 3 || !strcmp(argv[argc - 1], "--help")) {
printf("chroot [dir] [command] [arg arg2...]\n"); puts("chroot [dir] [command] [arg arg2...]");
return 0; return 0;
} }

View File

@ -68,7 +68,7 @@ int main(int argc, char **argv) {
break; break;
default: default:
printf("cmp [s] [file1] [file2] [skip1] [skip2]\n\t-s Silent\n"); puts("cmp [s] [file1] [file2] [skip1] [skip2]\n\t-s Silent");
return 0; return 0;
} }
} }

View File

@ -1,41 +1,50 @@
#define _XOPEN_SOURCE
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#include <sys/stat.h>
#include "get_stat.h"
const char *fmts[] = { const char *fmts[] = {
"%R", "%R",
"%T", "%T",
"%m.%d-%R", "%d-%m",
"%m.%d-%T", "%d-%m %H",
"%Y.%m.%d-%R", "%d-%m %R",
"%Y.%m.%d-%T", "%d-%m %T",
"%Y-%m-%d %R %z", "%d-%m-%Y",
"%Y-%m-%d %T %z", "%d-%m-%Y %H",
"%T %d-%m-%Y", "%d-%m-%Y %R",
"%H %d-%m-%Y", "%d-%m-%Y %T"
"%Y-%m-%d %H",
"%Y-%m-%d",
"%d-%m-%Y"
}; };
time_t parse_date(char *str) { time_t parse_date(char *str) {
time_t local = time(NULL); time_t local = time(NULL);
struct tm *tm = localtime(&local); struct tm *tm = localtime(&local);
char flag = 0;
for (size_t i = 0; i < sizeof(fmts) / sizeof(char *); i++) { for (size_t i = 0; i < sizeof(fmts) / sizeof(char *); i++) {
char *res = strptime(str, fmts[i], tm); char *res = strptime(str, fmts[i], tm);
if (res && *res == '\0') if (res && *res == '\0') {
flag = 1;
break; break;
} }
}
if (flag == 0) {
fprintf(stderr, "date: parsing: invalid format\n");
exit(1);
}
time_t rt = mktime(tm); time_t rt = mktime(tm);
if (rt == -1) { if (rt < 0) {
fprintf(stderr, "date: %s\n", strerror(errno)); if (rt == -1)
fprintf(stderr, "date: parsing: %s\n", strerror(errno));
else
fprintf(stderr, "date: parsing: invalid date\n");
exit(1); exit(1);
} }
@ -45,22 +54,17 @@ time_t parse_date(char *str) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
time_t t = time(NULL); time_t t = time(NULL);
char *fmt = "%a %b %e %H:%M:%S %Z %Y"; char *fmt = "%a %b %e %H:%M:%S %Z %Y";
char *r_flag = 0;
/* For -s flag */ /* For -s flag */
struct timespec ts; struct timespec ts;
int opt; int opt;
while ((opt = getopt(argc, argv, "s:d:r:u")) != -1) { while ((opt = getopt(argc, argv, "s:d:u")) != -1) {
switch (opt) { switch (opt) {
case 'r':
r_flag = optarg;
break;
case 's': case 's':
ts.tv_sec = parse_date(optarg); ts.tv_sec = parse_date(optarg);
if (clock_settime(CLOCK_REALTIME, &ts) < 0) { if (clock_settime(CLOCK_REALTIME, &ts) < 0) {
fprintf(stderr, "date: %s\n", strerror(errno)); fprintf(stderr, "date: settime: %s\n", strerror(errno));
return 1; return 1;
} }
@ -79,7 +83,10 @@ int main(int argc, char **argv) {
break; break;
default: default:
printf("date [rsdu] [+\"fmt\"]\n\t-s DATE Set new date\n\t-d DATE Print new date\n\t-u Work in UTC\n\t-r FILE Display last modification time of FILE\n"); puts("date [rsdu] [+\"fmt\"]\n\t-s TIME Set new date\n\t-d TIME Print new date\n\t-u Work in UTC\n\nRecognized TIME formats:");
for (size_t i = 0; i < sizeof(fmts) / sizeof(char *); i++)
puts(fmts[i]);
return 0; return 0;
} }
} }
@ -91,14 +98,6 @@ int main(int argc, char **argv) {
if (argv[0][0] == '+') if (argv[0][0] == '+')
fmt = argv[0] + 1; fmt = argv[0] + 1;
struct stat sb;
if (r_flag) {
if (mu_get_stat("date", r_flag, &sb))
return 1;
t = sb.st_mtime;
}
struct tm *tm = localtime(&t); struct tm *tm = localtime(&t);
char buf[256]; char buf[256];

View File

@ -46,6 +46,9 @@ int main(void) {
sigaddset(&set, SIGUSR1); sigaddset(&set, SIGUSR1);
sigaddset(&set, SIGUSR2); sigaddset(&set, SIGUSR2);
signal(SIGTERM, SIG_IGN);
signal(SIGINT, SIG_IGN);
/* Start main service */ /* Start main service */
sigprocmask(SIG_BLOCK, &set, NULL); sigprocmask(SIG_BLOCK, &set, NULL);
execute(INIT_START); execute(INIT_START);