add date
This commit is contained in:
parent
6cff13dd67
commit
daf3409726
2
build.sh
2
build.sh
|
@ -4,7 +4,7 @@ if [ -z $PROJECT_DIR ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z $CFLAGS ]; then
|
if [ -z $CFLAGS ]; then
|
||||||
CFLAGS="-pedantic -s -Os -flto -Werror -Wall -Wextra"
|
CFLAGS="-pedantic -s -Os -Werror -Wall -Wextra"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z $CC ]; then
|
if [ -z $CC ]; then
|
||||||
|
|
2
config.h
2
config.h
|
@ -20,7 +20,7 @@
|
||||||
#define MOUNT_OPT_SIZE 512
|
#define MOUNT_OPT_SIZE 512
|
||||||
|
|
||||||
/* nologin sleep */
|
/* nologin sleep */
|
||||||
#define NOLOGIN_SLEEP 60
|
#define NOLOGIN_SLEEP 0
|
||||||
|
|
||||||
/* colors for ls */
|
/* colors for ls */
|
||||||
#define LS_DIR_COLOR "\033[1;34m"
|
#define LS_DIR_COLOR "\033[1;34m"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Welcome!
|
|
@ -1,2 +1,2 @@
|
||||||
root::0:0:root:/usr/root:/bin/sh
|
root::0:0:root:/usr/root:/bin/sh
|
||||||
nobody:*:65534:65534:nobody:/nonexistent:/bin/false
|
nobody:*:65534:65534:nobody:/nonexistent:/bin/nologin
|
||||||
|
|
|
@ -5,5 +5,6 @@ mount -a
|
||||||
echo "Setuping hostname..."
|
echo "Setuping hostname..."
|
||||||
hostname -c /etc/hostname
|
hostname -c /etc/hostname
|
||||||
|
|
||||||
echo "Starting shell..."
|
reset
|
||||||
|
cat /etc/motd
|
||||||
env TERM="vt100" login
|
env TERM="vt100" login
|
||||||
|
|
|
@ -17,7 +17,6 @@ char *mu_make_path(const char *restrict prog_name, const char *restrict src, con
|
||||||
dst = "";
|
dst = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t len = strlen(src) + strlen(dst) + 2;
|
size_t len = strlen(src) + strlen(dst) + 2;
|
||||||
char *full_path = malloc(len + 1);
|
char *full_path = malloc(len + 1);
|
||||||
if (full_path == NULL) {
|
if (full_path == NULL) {
|
||||||
|
|
|
@ -6,13 +6,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) {
|
int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) {
|
||||||
if (pw->pw_passwd[0] == '\0' || pass[0] == '\0') {
|
if (pw->pw_passwd[0] == '\0' && pass[0] == '\0')
|
||||||
if (pass[0] == '\0')
|
return 0;
|
||||||
return 0;
|
|
||||||
|
|
||||||
fprintf(stderr, "%s: Incorrect password\n", prog_name);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pw->pw_passwd[0] == '!' || pw->pw_passwd[0] == '*') {
|
if (pw->pw_passwd[0] == '!' || pw->pw_passwd[0] == '*') {
|
||||||
fprintf(stderr, "%s: Denied\n", prog_name);
|
fprintf(stderr, "%s: Denied\n", prog_name);
|
||||||
|
@ -22,6 +17,7 @@ int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) {
|
||||||
if (!strcmp(pass, pw->pw_passwd))
|
if (!strcmp(pass, pw->pw_passwd))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
fprintf(stderr, "%s: Incorrect password\n", prog_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
project_dir=$(pwd)
|
||||||
|
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
|
@ -0,0 +1,98 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.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"
|
||||||
|
};
|
||||||
|
|
||||||
|
time_t parse_date(char *str) {
|
||||||
|
time_t local = time(NULL);
|
||||||
|
struct tm *tm = localtime(&local);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sizeof(fmts) / sizeof(char *); i++) {
|
||||||
|
char *res = strptime(str, fmts[i], tm);
|
||||||
|
if (res && *res == '\0')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t rt = mktime(tm);
|
||||||
|
if (rt == -1) {
|
||||||
|
fprintf(stderr, "date: %s\n", strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rt;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
time_t t = time(NULL);
|
||||||
|
char *fmt = "%a %b %e %H:%M:%S %Z %Y";
|
||||||
|
|
||||||
|
/* For -s flag */
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
int opt;
|
||||||
|
while ((opt = getopt(argc, argv, "s:d:u")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 's':
|
||||||
|
ts.tv_sec = parse_date(optarg);
|
||||||
|
if (clock_settime(CLOCK_REALTIME, &ts) < 0) {
|
||||||
|
fprintf(stderr, "date: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case 'd':
|
||||||
|
t = parse_date(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'u':
|
||||||
|
if (setenv("TZ", "UTC0", 1) < 0) {
|
||||||
|
fprintf(stderr, "date: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf("date\n\t[-s DATE Set new date]\n\t[-d DATE Print new date]\n\t[-u Work in UTC]\n");
|
||||||
|
printf("\nFormats:\n");
|
||||||
|
for (size_t i = 0; i < sizeof(fmts) / sizeof(char *); i++)
|
||||||
|
printf("\t%s\n", fmts[i]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
argv += optind;
|
||||||
|
argc -= optind;
|
||||||
|
|
||||||
|
if (argc != 0)
|
||||||
|
if (argv[0][0] == '+')
|
||||||
|
fmt = argv[0] + 1;
|
||||||
|
|
||||||
|
struct tm *tm = localtime(&t);
|
||||||
|
|
||||||
|
char buf[256];
|
||||||
|
strftime(buf, sizeof(buf), fmt, tm);
|
||||||
|
|
||||||
|
puts(buf);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -28,7 +28,9 @@ unsigned int h_flag;
|
||||||
unsigned int s_flag;
|
unsigned int s_flag;
|
||||||
unsigned int i_flag;
|
unsigned int i_flag;
|
||||||
unsigned int p_flag;
|
unsigned int p_flag;
|
||||||
int (*sorter)(const void *p1, const void *p2) = NULL;
|
|
||||||
|
int sortd(const void *p1, const void *p2);
|
||||||
|
int (*sorter)(const void *p1, const void *p2) = sortd;
|
||||||
|
|
||||||
struct d_node {
|
struct d_node {
|
||||||
/* basename */
|
/* basename */
|
||||||
|
@ -297,6 +299,13 @@ int sorts(const void *p1, const void *p2) {
|
||||||
return (*(struct d_node **)p2)->stats.st_size - (*(struct d_node **)p1)->stats.st_size;
|
return (*(struct d_node **)p2)->stats.st_size - (*(struct d_node **)p1)->stats.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sortd(const void *p1, const void *p2) {
|
||||||
|
struct d_node *l1 = *(struct d_node **)p1;
|
||||||
|
struct d_node *l2 = *(struct d_node **)p2;
|
||||||
|
|
||||||
|
return strlen(l1->name) - strlen(l2->name);
|
||||||
|
}
|
||||||
|
|
||||||
int ls(const char *dir_name, int label, struct winsize w) {
|
int ls(const char *dir_name, int label, struct winsize w) {
|
||||||
size_t files = 0;
|
size_t files = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
|
@ -36,6 +36,7 @@ void login(const struct passwd *pw) {
|
||||||
setenv("SHELL", shell, 1);
|
setenv("SHELL", shell, 1);
|
||||||
setenv("USER", pw->pw_name, 1);
|
setenv("USER", pw->pw_name, 1);
|
||||||
setenv("LOGNAME", pw->pw_name, 1);
|
setenv("LOGNAME", pw->pw_name, 1);
|
||||||
|
setenv("PATH", "/bin", 1);
|
||||||
|
|
||||||
if (chdir(pw->pw_dir) < 0) {
|
if (chdir(pw->pw_dir) < 0) {
|
||||||
fprintf(stderr, "login: %s\n", strerror(errno));
|
fprintf(stderr, "login: %s\n", strerror(errno));
|
||||||
|
@ -50,7 +51,8 @@ struct passwd *proccess_input(char *hostname) {
|
||||||
static char psswd[512];
|
static char psswd[512];
|
||||||
|
|
||||||
/* Username */
|
/* Username */
|
||||||
printf("Login on %s:\n", hostname);
|
printf("Login on %s: ", hostname);
|
||||||
|
fflush(stdout);
|
||||||
if (!mu_get_string("login", user, sizeof(user)))
|
if (!mu_get_string("login", user, sizeof(user)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -61,16 +63,17 @@ struct passwd *proccess_input(char *hostname) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Password */
|
/* Password */
|
||||||
printf("\nPassword:\n");
|
printf("Password: ");
|
||||||
|
fflush(stdout);
|
||||||
if (hide_input(STDIN_FILENO, 1))
|
if (hide_input(STDIN_FILENO, 1))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!mu_get_string("login", psswd, sizeof(psswd)))
|
if (!mu_get_string("login", psswd, sizeof(psswd)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
if (pw_check("login", pw, psswd)) {
|
if (pw_check("login", pw, psswd)) {
|
||||||
memset(psswd, '\0', sizeof(psswd));
|
memset(psswd, '\0', sizeof(psswd));
|
||||||
fprintf(stderr, "login: Incorrect password\n");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue