From bb8d7d0da1664aafb101bc32e4641155af9c9c50 Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Wed, 6 Dec 2023 20:53:05 +1000 Subject: [PATCH] add group file, and user/group data functions getpw*/getgr* --- clite/commands.js | 21 +++++--- clite/core.js | 128 +++++++++++++++++++++++++++++++++++++++------- clite/libstd.js | 24 +++++++++ 3 files changed, 147 insertions(+), 26 deletions(-) diff --git a/clite/commands.js b/clite/commands.js index 5564351..e93e8c5 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -54,13 +54,21 @@ Options: function writeNodeData(st,fd) { if (long) { + var pw = stdlib.getpwuid(st.uid); + var gr = stdlib.getgrgid(st.gid); + var uname = st.uid.toString(); + var gname = st.gid.toString(); + if (pw) + uname = pw.pw_name; + if (gr) + gname = gr.gr_name; if (st.type == stdio.types.FT_LINK) { var d = stdio.readAll(fd); if (!d) d = '?'; - stdio.printf(st.perms+'\t'+st.uid+'\t'+st.gid+'\t'+st.name+' -> '+d); + stdio.printf('%s%16s%16s%16s -> %s\n',st.perms,uname,gname,st.name,d); }else{ - stdio.printf(st.perms+'\t'+st.uid+'\t'+st.gid+'\t'+st.name); + stdio.printf('%s%16s%16s%16s\n',st.perms,uname,gname,st.name); } }else{ stdio.printf(st.name); @@ -1192,14 +1200,13 @@ clite.commands.load('test',function(args,env,io) { stdio.printf('uid:%d',stdlib.getuid()); stdio.printf('%#15x:%15o:%15.5f:%0$15.5f:%%:',10,12,8.123456789); function rcb(data) { - stdio.printf(data); + stdio.write(io.stdout,data); + var u = stdlib.getpwnam(data); + if (u) + stdio.printf('%s %d %d\n',u.pw_name,u.pw_uid,u.pw_gid); io.exit(0); } - var fd = clite.io.openp(io.pid,'/var/logs',stdio.flags.O_RDONLY,function(fd) { - alert(fd.node.data.content); - }); - stdio.read(io.stdin,rcb); return null; diff --git a/clite/core.js b/clite/core.js index 741b688..2aaa93b 100644 --- a/clite/core.js +++ b/clite/core.js @@ -40,9 +40,9 @@ var clite = { }, file:function(name,callback) { if (window.location.protocol == 'file:') { // this is a dirty hack and I hate it, just let me open a file: path! - //clite.term.setCustom({type:'file',callback:callback}); - //clite.shell.writeLine('open file: '+name); - //return; + clite.term.setCustom({type:'file',callback:callback}); + clite.term.writeLine('open file: '+name); + return; // fuck it, I'll just update about:config in firefox } @@ -264,6 +264,19 @@ PATH=/bin n.data.content = ` root:x:0:0:root:/root:/bin/sh guest:x:1:1:guest:/usr/home/guest:/bin/sh +`; + // TODO: check cookies for a local user + n.perms = '-rw-r--r--'; + // /etc/passwd contains user account details + vfsapi.mkFile(0,'/etc/group'); + var n = vfsapi.getNode(0,'/etc/group'); + if (!n) { + clite.log.write('group config failure'); + return false; + } + n.data.content = ` +root:x:0: +guest:x:1: `; // TODO: check cookies for a local user n.perms = '-rw-r--r--'; @@ -723,21 +736,35 @@ clite.proc = { clite.user = { init:function(vfsapi) { // returns true if there's a user login or false for guest - var users = [{ - name:'root', - uid:0, - gid:0, - groups:[], - env:{ - HOME:'/', - USER:this.name, - } - }]; + var data = { + users:[{ + name:'root', + uid:0, + gid:0, + groups:[], + env:{ + HOME:'/', + USER:this.name, + } + }], + groups:[{ + name:'root', + gid:0, + users:[] + }] + }; var env = {}; function getUser(uid) { - for (var i=0; i