-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: wargame action: commit revision: path_from: revision_from: 9268789dedff01bbe7bbaed3248977e4639bdfe8: path_to: revision_to:
commit 9268789dedff01bbe7bbaed3248977e4639bdfe8 Author: epoch <epoch@thebackupbox.net> Date: Tue Mar 28 21:47:34 2023 +0000 forced useradd to use the uid I want it to use, compressed the name[] assignment. added comments for each header. diff --git a/tools/newuser.c b/tools/newuser.c
--- a/tools/newuser.c +++ b/tools/newuser.c @@ -1,20 +1,19 @@ -#include <stdio.h> -#include <ctype.h> //isalpha I think +#include <ctype.h> //isalpha #include <unistd.h> //execv +#include <grp.h> //getpwuid +#include <pwd.h> //getgrgid +#include <stdio.h> // sprintf #define DEFAULT_PASSWORD_HASH "$6$aUL4XtcGCPT6Oj/x$sa4MUe2TC1rO3XnkzFcS4OjoTrHXE9zBp6N5vzaJcOLaTMjIZTUKAzsKEi49Q7gbK4CZm869aIkYJxISsQjp51" int main(int argc,char *argv[]) { int i; - char *name[6]; - for(i=0;argv[1][i];i++) { - if(!isalpha(argv[1][i])) return 1;//fuck off with your weird usernames - } - name[0]="/usr/sbin/useradd"; - name[1]="-m"; - name[2]="-p"; - name[3]=DEFAULT_PASSWORD_HASH; - name[4]=argv[1]; - name[5]=0; + uid_t uid; + char struid[128];//way more than enough for any unsigned integer representation... right? + if(argc < 2) return 2; + for(i=0;argv[1][i];i++) if(!isalpha(argv[1][i])) return 1; + for(uid=1000;getpwuid(uid) || getgrgid(uid);uid++); // find first open uid and gid pair that are the same + sprintf(struid,"%u",uid); + char *name[] = { "/usr/sbin/useradd", "-m", "-u", struid, "-p", DEFAULT_PASSWORD_HASH, argv[1], 0 }; execv(name[0],name); }
-----END OF PAGE-----
-- Response ended
-- Page fetched on Sun Jun 2 15:29:36 2024