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
Other:
watch
ps
sysctl
ping
ncat
@ -31,10 +29,10 @@ Other:
swapon
swapoff
hexdump
sed
Loginutils:
userctl
groupctl
usersctl
getty
Modutils:

View File

@ -5,7 +5,7 @@
#define BUF_SIZE 1024 * 1024
#ifdef _SHRED_C
/* Random source (shred) */
/* source of random (shred) */
#define RAND_SOURCE "/dev/urandom"
#endif
@ -16,7 +16,7 @@
#ifdef _PW_CHECK_H
/* 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];
#endif

View File

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

View File

@ -11,12 +11,11 @@
void dec_salt(void) {
size_t 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';
}
/* Using not only there */
char *enc_password(const char *prog_name, const char *pass, const char *salt) {
if (salt == NULL)
dec_salt();

View File

@ -32,7 +32,7 @@ int main(int argc, char **argv) {
break;
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;
}
}

View File

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

View File

@ -56,7 +56,7 @@ int main(int argc, char **argv) {
break;
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;
}
}

View File

@ -71,7 +71,7 @@ int main(int argc, char **argv) {
break;
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;
}
}

View File

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

View File

@ -68,7 +68,7 @@ int main(int argc, char **argv) {
break;
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;
}
}

View File

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

View File

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