first commit
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
# BusyBox, Orwellian Edition
|
||||
|
||||
Given that states and countries are now requiring that operating systems report
|
||||
the age of users, it is important that BusyBox be able to comply. Why? BusyBox
|
||||
is used in embedded devices that qualify for regulation under these bills (such
|
||||
as California's [AB-1043](https://leginfo.legislature.ca.gov/faces/billTextClient.xhtml?bill_id=202520260AB1043)).
|
||||
For most hardware, this would actually amount to just reporting epoc for root,
|
||||
as most devices won't directly have users. Applications on those may, but those
|
||||
usually have their own user management features.
|
||||
|
||||
This patch adds the `-b` option to BusyBox's adduser, and will record a birthday
|
||||
in YYYYMMDD format. This can then be used to determine age, and/or the age
|
||||
bracket of the user via the standard UNIX shell which serves as the UNIX
|
||||
API/ABI, and thus makes BusyBox compliant with the law. The two UNIX commands
|
||||
added here are `howoldami` and `useragerange`.
|
||||
@@ -0,0 +1,67 @@
|
||||
--- loginutils/adduser.c.orig
|
||||
+++ loginutils/adduser.c
|
||||
@@ -44,6 +44,7 @@
|
||||
//usage: "\n -H Don't create home directory"
|
||||
//usage: "\n -u UID User id"
|
||||
//usage: "\n -k SKEL Skeleton directory (/etc/skel)"
|
||||
+//usage: "\n -b DOB Date of birth (YYYYMMDD)"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
@@ -61,6 +62,7 @@
|
||||
#define OPT_DONT_MAKE_HOME (1 << 6)
|
||||
#define OPT_UID (1 << 7)
|
||||
#define OPT_SKEL (1 << 8)
|
||||
+#define OPT_DOB (1 << 9)
|
||||
|
||||
/* remix */
|
||||
/* recoded such that the uid may be passed in *p */
|
||||
@@ -128,6 +130,7 @@
|
||||
"no-create-home\0" No_argument "H"
|
||||
"uid\0" Required_argument "u"
|
||||
"skel\0" Required_argument "k"
|
||||
+ "dob\0" Required_argument "b"
|
||||
;
|
||||
|
||||
/*
|
||||
@@ -141,6 +144,7 @@
|
||||
unsigned opts;
|
||||
char *uid;
|
||||
const char *skel = "/etc/skel";
|
||||
+ char *dob = NULL;
|
||||
|
||||
/* got root? */
|
||||
if (geteuid()) {
|
||||
@@ -151,12 +155,12 @@
|
||||
pw.pw_dir = NULL;
|
||||
|
||||
opts = getopt32long(argv, "^"
|
||||
- "h:g:s:G:DSHu:k:"
|
||||
+ "h:g:s:G:DSHu:k:b:"
|
||||
/* at least one and at most two non-option args */
|
||||
/* disable interactive passwd for system accounts */
|
||||
"\0" "-1:?2:SD",
|
||||
adduser_longopts,
|
||||
- &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell,
|
||||
- &usegroup, &uid, &skel
|
||||
+ &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell,
|
||||
+ &usegroup, &uid, &skel, &dob
|
||||
);
|
||||
if (opts & OPT_UID)
|
||||
@@ -200,6 +204,16 @@
|
||||
free(p);
|
||||
#endif
|
||||
|
||||
+ /* Record date of birth if specified */
|
||||
+ if (opts & OPT_DOB) {
|
||||
+ FILE *f = fopen("/etc/birthdays", "a");
|
||||
+ if (f) {
|
||||
+ fprintf(f, "%s:x:%s:\n", pw.pw_name, dob);
|
||||
+ fclose(f);
|
||||
+ } else {
|
||||
+ bb_perror_msg("/etc/birthdays");
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
/* add to group */
|
||||
addgroup_wrapper(&pw, usegroup);
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
username=$(whoami)
|
||||
dob=$(grep $username /etc/birthdays | cut -f 3 -d ':')
|
||||
today=$(date +%Y%m%d)
|
||||
age=$(echo "$today - $dob" | bc -l | cut -f 1 -d '.')
|
||||
printf "%s%b" "$age" "\n"
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
age=$(howoldami)
|
||||
|
||||
if [ $age -lt 13 ]; then
|
||||
echo "User is under the age of 13."
|
||||
elif [ $age -ge 13 ] && [ $age -lt 16 ]; then
|
||||
echo "User is under the age of 16, but at least 13."
|
||||
elif [ $age -ge 16 ] && [ $age -lt 18 ]; then
|
||||
echo "User is at least 16, but younger than 18."
|
||||
else
|
||||
echo "User is over 18"
|
||||
fi
|
||||
@@ -0,0 +1,2 @@
|
||||
# username:x:YYYYMMDD:
|
||||
root:x:19700101:
|
||||
Reference in New Issue
Block a user