fixed login/pw_chech added cryptpw
This commit is contained in:
parent
b752f9d46a
commit
94a0c8c60c
18
config.h
18
config.h
|
@ -4,18 +4,31 @@
|
||||||
/* (cat tee wc xargs rev split) text buffer */
|
/* (cat tee wc xargs rev split) text buffer */
|
||||||
#define BUF_SIZE 2048
|
#define BUF_SIZE 2048
|
||||||
|
|
||||||
|
#ifdef _SHRED_C
|
||||||
/* Random source (shred) */
|
/* Random source (shred) */
|
||||||
#define RAND_SOURCE "/dev/urandom"
|
#define RAND_SOURCE "/dev/urandom"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _HEAD_C
|
||||||
/* format for printf (head) */
|
/* format for printf (head) */
|
||||||
#define HEAD_FMT "==> %s <==\n"
|
#define HEAD_FMT "==> %s <==\n"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _PW_CHECK_H
|
||||||
|
/* Pw_check. Salt for crypt() */
|
||||||
|
int MU_SALT_ENC[] = {'s', 'a', 'l', 't'};
|
||||||
|
char MU_SALT_BUF[sizeof(MU_SALT_ENC) + 1];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MOUNT_C
|
||||||
/* mount config */
|
/* mount config */
|
||||||
#define MOUNT_CFG "/etc/fstab"
|
#define MOUNT_CFG "/etc/fstab"
|
||||||
#define MOUNT_DEF_FS "ext4"
|
#define MOUNT_DEF_FS "ext4"
|
||||||
#define MOUNT_LIST "/proc/mounts"
|
#define MOUNT_LIST "/proc/mounts"
|
||||||
#define MOUNT_OPT_SIZE 512
|
#define MOUNT_OPT_SIZE 512
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _LS_C
|
||||||
/* colors for ls */
|
/* colors for ls */
|
||||||
#define LS_DIR_COLOR "\033[1;34m"
|
#define LS_DIR_COLOR "\033[1;34m"
|
||||||
#define LS_LINK_COLOR "\033[1;35m"
|
#define LS_LINK_COLOR "\033[1;35m"
|
||||||
|
@ -23,16 +36,19 @@
|
||||||
#define LS_FIFO_COLOR "\033[1;35m"
|
#define LS_FIFO_COLOR "\033[1;35m"
|
||||||
#define LS_BLOCK_COLOR "\033[1;33m"
|
#define LS_BLOCK_COLOR "\033[1;33m"
|
||||||
#define LS_EXE_COLOR "\033[1;32m"
|
#define LS_EXE_COLOR "\033[1;32m"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Init scripts */
|
|
||||||
#ifdef INIT
|
#ifdef INIT
|
||||||
|
/* Init scripts */
|
||||||
char *INIT_POWEROFF[] = {"/etc/rc.poweroff", NULL};
|
char *INIT_POWEROFF[] = {"/etc/rc.poweroff", NULL};
|
||||||
char *INIT_START[] = {"/etc/rc.init", NULL};
|
char *INIT_START[] = {"/etc/rc.init", NULL};
|
||||||
#define INIT_MSG "Starting micro-init..."
|
#define INIT_MSG "Starting micro-init..."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _UNAME_C
|
||||||
/* Os name for uname */
|
/* Os name for uname */
|
||||||
/* #define OS_NAME "unknow" */
|
/* #define OS_NAME "unknow" */
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Options: To disable, comment line */
|
/* Options: To disable, comment line */
|
||||||
|
|
||||||
|
|
|
@ -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/nologin
|
nobody:*:65534:65534:nobody:/nonexistent:/bin/false
|
||||||
|
|
|
@ -3,7 +3,34 @@
|
||||||
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
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 + 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Using not only there */
|
||||||
|
char *enc_password(const char *prog_name, const char *pass, const char *salt) {
|
||||||
|
if (salt == NULL)
|
||||||
|
dec_salt();
|
||||||
|
|
||||||
|
char *cpass = crypt(pass, (salt == NULL) ? MU_SALT_BUF : salt);
|
||||||
|
if (cpass == NULL) {
|
||||||
|
if (prog_name != NULL)
|
||||||
|
fprintf(stderr, "%s: %s\n", prog_name, strerror(errno));
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cpass;
|
||||||
|
}
|
||||||
|
|
||||||
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')
|
||||||
|
@ -16,7 +43,11 @@ int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(pass, pw->pw_passwd))
|
char *cpass = enc_password(prog_name, pass, NULL);
|
||||||
|
if (cpass == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (!strcmp(pw->pw_passwd, cpass))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (prog_name != NULL)
|
if (prog_name != NULL)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#define _HEAD_C
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
|
@ -137,4 +137,3 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
return def_ids(uid, pwd);
|
return def_ids(uid, pwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#define _LS_C
|
||||||
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -104,7 +106,7 @@ struct d_node **list(const char *path, size_t *nfiles, int *ret) {
|
||||||
if (dn == NULL)
|
if (dn == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
struct d_node **dir = malloc(*nfiles * sizeof(struct d_node *));
|
struct d_node **dir = malloc((*nfiles + 1) * sizeof(struct d_node *));
|
||||||
if (dir == NULL) {
|
if (dir == NULL) {
|
||||||
fprintf(stderr, "ls: malloc failed\n");
|
fprintf(stderr, "ls: malloc failed\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "nohup: missing operand\n");
|
printf("nohup: missing operand\nnohup [cmd]\n");
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fork() != 0)
|
if (fork() != 0)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#define _SHRED_C
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#define UNAME_C
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
3
src/loginutils/cryptpw/build.sh
Executable file
3
src/loginutils/cryptpw/build.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
project_dir=$(pwd)
|
||||||
|
echo ./*.c $CFLAGS -o $OUTPUT$(basename $project_dir) | xargs $CC
|
20
src/loginutils/cryptpw/cryptpw.c
Normal file
20
src/loginutils/cryptpw/cryptpw.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "pw_check.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
if (argc < 2) {
|
||||||
|
printf("cryptpw: missing operand\ncryptpw [password] [own salt]\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *salt = NULL;
|
||||||
|
if (argc > 2)
|
||||||
|
salt = argv[2];
|
||||||
|
|
||||||
|
char *cpass = enc_password("cryptpw", argv[1], salt);
|
||||||
|
if (cpass == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
puts(cpass);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -27,8 +27,8 @@ void print(double diff, char *str, double min) {
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
fprintf(stderr, "spark: missing operands\n");
|
printf("spark: missing operands\nspark [num1] [num2]...\n");
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int r_flag = 0;
|
unsigned int r_flag = 0;
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "time: missing operand\n");
|
printf("time: missing operand\ntime [cmd]\n");
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long ticks = sysconf(_SC_CLK_TCK);
|
long ticks = sysconf(_SC_CLK_TCK);
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#define _MOUNT_C
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#define _MOUNT_C
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user