Map new SQL users to explicitly selected existing Linux accounts

This commit is contained in:
2026-12-01 12:41:25 +00:00
parent b131dcc9d6
commit 53e6c27960
12 changed files with 166 additions and 12 deletions

View File

@@ -4,8 +4,9 @@ set -euo pipefail
cd "$(dirname "$0")/.."
root=$PWD
scratch=$(mktemp -d "$root/build/bindery-test.XXXXXX")
mkdir -p "$scratch"/{config,state/bindery,vol/SYS/public,sbin}
mkdir -p "$scratch"/{config,state/bindery,identities,vmestate,vol/SYS/public,sbin}
cp upstream/build/src/{nwserv,nwbind,nwconn,ncpserv,dbmtool} "$scratch/sbin/"
cp build/mars_vme "$scratch/sbin/"
cp build/mars-pcapd "$scratch/sbin/"
cat > "$scratch/config/nwserv.conf" <<'CONF'
2 MARSTEST
@@ -23,14 +24,19 @@ s=$1
mount --make-rprivate /
mount --bind "$s/config" /usr/local/etc/mars_nwe
mount --bind "$s/state" /var/lib/mars_nwe
mount --bind "$s/identities" /var/lib/mars-identities
mount --bind "$s/vmestate" /var/lib/mars-vme
mount --bind "$s/vol" /var/mars_nwe
mount --bind "$s/sbin" /usr/local/sbin
mount -t tmpfs tmpfs /run
mkdir -m700 /run/mars-pcap
ip link set lo up
/usr/local/sbin/mars-pcapd --offline-test >"$s/broker.log" 2>&1 &
for i in {1..50}; do [[ ! -S /run/mars-pcap/transport.sock ]] || break; sleep .1; done
/usr/local/sbin/nwserv >"$s/server.log" 2>&1 &
for i in {1..100}; do [[ ! -S /run/mars-pcap/admin.sock ]] || break; sleep .1; done
/usr/local/sbin/mars_vme --bind 127.0.0.1 --port 18789 --no-autostart >"$s/web.log" 2>&1 &
for i in {1..100}; do if curl -fsS http://127.0.0.1:18789/login >/dev/null 2>&1; then break; fi; sleep .1; done
python3 - <<'PY'
import socket,json
@@ -42,6 +48,22 @@ assert u.get('unix')=='nobody',u
props=query({'op':'properties','name':'SUPERVISOR','type':1})['properties']
names={p['name'] for p in props}
assert {'UNIX_USER','PASSWORD','SECURITY_EQUALS',"GROUPS_I'M_IN"}.issubset(names), names
import urllib.request,http.cookiejar
base='http://127.0.0.1:18789';csrf=''
opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar()))
def api(path,data=None):
req=urllib.request.Request(base+path,data=json.dumps(data).encode() if data is not None else None,headers={'Origin':base,'Content-Type':'application/json','X-Mars-CSRF':csrf})
with opener.open(req,timeout=10) as response:return json.load(response)
api('/api/login',{'user':'admin','password':'admin'});csrf=api('/api/state')['csrf']
api('/api/password',{'current':'admin','new':'LOCALTESTPASS123','repeat':'LOCALTESTPASS123'})
api('/api/login',{'user':'admin','password':'LOCALTESTPASS123'});csrf=api('/api/state')['csrf']
users=api('/api/identities')['localUsers'];assert users
chosen=users[0]
for name in ['MAPALICE','MAPBOB']:
result=api('/api/identities',dict(op='create',name=name,password='TESTPASS123',unix=chosen['name'],uid=chosen['uid'],gid=chosen['gid'],sharedConfirmed=True,confirm=True))
assert result['unix']==chosen['name']
mappings=api('/api/identities')['localMappings'];assert len(mappings)==2 and all(x['status']=='linked' for x in mappings),mappings
print('PASS isolated real HTTP + nwbind + SQLite: two independent NetWare users share the chosen Linux account')
print('PASS isolated real nwbind: SUPERVISOR mapping and independent properties', sorted(names))
PY
NS

View File

@@ -24,8 +24,9 @@ def fixture(source,path,body):
if path=='/api/identities':
if body:
assert body['confirm'] and body['name']=='ALICE' and len(body['password'])==20
created+=1;objects.append({'name':'ALICE','type':1,'unix':'marsv200000000','id':3,'disabled':False});return {'alias':'marsv200000000','uid':200000000}
return dict(wrappedBindery=True,liveComplete=True,databaseAvailable=True,identities=[{'name':'ALICE','alias':'marsv200000000','uid':200000000,'status':'linked'}] if created else [],issues=[])
assert body['unix']=='chris' and body['uid']==1000 and body['gid']==1000 and body['sharedConfirmed']
created+=1;objects.append({'name':'ALICE','type':1,'unix':'chris','id':3,'disabled':False});return {'alias':'chris','unix':'chris','uid':1000}
return dict(localUsers=[{'name':'chris','uid':1000,'gid':1000}],localMappings=[],wrappedBindery=True,liveComplete=True,databaseAvailable=True,identities=[{'name':'ALICE','alias':'marsv200000000','uid':200000000,'status':'linked'}] if created else [],issues=[])
if path=='/api/bindery' and body['op']=='objects':return {'objects':objects}
raise AssertionError((path,body))
with sync_playwright() as p:
@@ -38,7 +39,7 @@ with sync_playwright() as p:
page.locator('#directoryNext').click();page.locator('#directoryTree').fill('INVALID NAME');page.locator('#directoryNext').click();assert 'zulässige' in page.locator('#directoryMessage').inner_text();page.locator('#directoryTree').fill('MARS_TREE');page.locator('#directoryNext').click();page.locator('#directoryAuto').click();page.locator('#directoryNext').click();assert 'Tree / Baum: leer lassen' in page.locator('#directoryClient').input_value();page.locator('#directorySave').click();page.wait_for_function("document.getElementById('directoryMessage').textContent.includes('gespeichert')");assert config['placements']
# A failed reload must not permit a save of stale data.
fail=True;page.locator('#directoryBack').click();page.locator('#directoryBack').click();page.locator('#directoryBack').click();page.locator('#directoryReload').click();page.wait_for_function("document.getElementById('directoryMessage').textContent.includes('Bitte erneut laden')");assert page.locator('#directoryNext').is_disabled();fail=False;page.locator('#directoryReload').click();page.wait_for_function("!document.getElementById('directoryNext').disabled");page.locator('#directoryBindery').click();page.wait_for_function("document.getElementById('bindSummary').textContent.includes('2 Objekte')")
page.locator('#createUser').click();page.locator('[name=name]').fill('alice');page.get_by_role('button',name='Sicheres Kennwort erzeugen').click();pw=page.locator('[name=password]').input_value();assert len(pw)==20 and all(c in '0123456789ABCDEF' for c in pw);page.locator('#actionSubmit').click();page.wait_for_function("document.getElementById('bindSummary').textContent.includes('3 Objekte')");assert created==1;assert page.locator('[name=password]').input_value()==''
page.locator('#createUser').click();page.locator('[name=name]').fill('alice');assert page.locator('[name=unix]').input_value()=='';page.locator('[name=unix]').select_option('chris');page.get_by_role('button',name='Sicheres Kennwort erzeugen').click();pw=page.locator('[name=password]').input_value();assert len(pw)==20 and all(c in '0123456789ABCDEF' for c in pw);page.locator('#actionSubmit').click();page.wait_for_function("document.getElementById('bindSummary').textContent.includes('3 Objekte')");assert created==1;assert page.locator('[name=password]').input_value()==''
page.evaluate("()=>document.querySelectorAll('dialog[open]').forEach(d=>d.close())")
page.locator('#ncpIpOpen').click();page.wait_for_function("!document.getElementById('ncpPresetIp').disabled")
page.locator('#ncpPresetIp').click();assert page.locator('#ncpIpEnabled').is_checked();assert page.locator('#ncpIpSlp').is_checked();assert page.locator('#ncpIpRestart').is_disabled()

View File

@@ -0,0 +1,31 @@
#define _GNU_SOURCE
#include "identity_api.h"
#include "identity.h"
#include <assert.h>
#include <pwd.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
static char names[4][48],accounts[4][20];static int count,fail_create;
json_object *bindery_call(json_object *q){
json_object *o=json_object_new_object();const char *op=js(q,"op");
if(!strcmp(op,"identity-capabilities"))json_object_object_add(o,"identityVersion",json_object_new_int(1));
else if(!strcmp(op,"objects")){json_object *a=json_object_new_array();for(int i=0;i<count;i++){json_object *x=json_object_new_object();addstr(x,"name",names[i]);addstr(x,"unix",accounts[i]);json_object_object_add(x,"type",json_object_new_int(1));json_object_array_add(a,x);}json_object_object_add(o,"objects",a);}
else if(!strcmp(op,"create-user")){if(fail_create)addstr(o,"error","test failure");else{assert(count<4);snprintf(names[count],48,"%s",js(q,"name"));snprintf(accounts[count],20,"%s",js(q,"unix"));count++;}}
else assert(0);
return o;
}
static void rejected(json_object *q){int before=count;json_object *r=identity_create(q);assert(get(r,"error")&&count==before);json_object_put(r);}
int main(void){
unlink(MARS_ID_DB);json_object *r=identity_status(),*users=get(r,"localUsers");assert(json_object_array_length(users)>0);json_object *u=json_object_array_get_idx(users,0);char account[20];snprintf(account,sizeof account,"%s",js(u,"name"));int uid=json_object_get_int(get(u,"uid")),gid=json_object_get_int(get(u,"gid"));json_object_put(r);
json_object *q=json_tokener_parse("{\"name\":\"ALICE\",\"password\":\"TESTPASS1\",\"sharedConfirmed\":true}");addstr(q,"unix","root");json_object_object_add(q,"uid",json_object_new_int(0));json_object_object_add(q,"gid",json_object_new_int(0));rejected(q);
addstr(q,"unix",account);json_object_object_add(q,"uid",json_object_new_int(uid+1));json_object_object_add(q,"gid",json_object_new_int(gid));rejected(q);
json_object_object_add(q,"uid",json_object_new_int(uid));json_object_object_add(q,"sharedConfirmed",json_object_new_boolean(0));rejected(q);json_object_object_add(q,"sharedConfirmed",json_object_new_boolean(1));
r=identity_create(q);assert(!get(r,"error")&&count==1);assert(!strcmp(js(r,"unix"),account));json_object_put(r);assert(identity_local_managed("ALICE"));rejected(q);
addstr(q,"name","BOB");r=identity_create(q);assert(!get(r,"error")&&count==2);json_object_put(r);assert(!strcmp(accounts[0],accounts[1]));
r=identity_status();assert(json_object_array_length(get(r,"localMappings"))==2);assert(!strcmp(js(json_object_array_get_idx(get(r,"localMappings"),0),"status"),"linked"));assert(!strstr(json_object_to_json_string(r),"TESTPASS1"));json_object_put(r);
fail_create=1;addstr(q,"name","FAILED");rejected(q);assert(identity_local_managed("FAILED"));fail_create=0;rejected(q);
sqlite3 *db;assert(!mars_id_open(&db,1));assert(sqlite3_exec(db,"UPDATE local_mappings SET uid=uid+1 WHERE name='ALICE'",NULL,NULL,NULL)==SQLITE_OK);sqlite3_close(db);
r=identity_status();assert(!strcmp(js(json_object_array_get_idx(get(r,"localMappings"),0),"status"),"account-changed"));json_object_put(r);
json_object_put(q);unlink(MARS_ID_DB);puts("PASS SQL local mappings: root/stale ID rejection, explicit confirmation, shared account, duplicates, failed reservation, identity drift, no passwords");
}