implement Styxd; include "sys.m"; sys: Sys; stdin, stderr: ref Sys->FD; include "keyring.m"; kr: Keyring; include "security.m"; auth: Auth; include "draw.m"; Styxd: module { init: fn(ctxt: ref Draw->Context, argv: list of string); }; # argv is a list of Inferno supported algorithms from Security->Auth init(nil: ref Draw->Context, argv: list of string) { sys = load Sys Sys->PATH; stdin = sys->fildes(0); stderr = sys->open("/dev/cons", sys->OWRITE); auth = load Auth Auth->PATH; if(auth == nil){ sys->fprint(stderr, "styxd: can't load module Auth\n"); exit; } error := auth->init(); if(error != nil){ sys->fprint(stderr, "styxd: %s\n", error); exit; } user := user(); kr = load Keyring Keyring->PATH; ai := kr->readauthinfo("/usr/"+user+"/keyring/default"); # # let auth->server handle nil ai # if(ai == nil){ # sys->fprint(stderr, "styxd: readauthinfo failed: %r\n"); # exit; # } # if(argv == nil){ sys->fprint(stderr, "styxd: no algorithm list\n"); exit; } (fd, info_or_err) := auth->server(argv, ai, stdin, 1); if(fd == nil ){ sys->fprint(stderr, "styxd: %s\n", info_or_err); exit; } sys->pctl(sys->FORKNS|sys->FORKENV, nil); if(sys->export(fd, sys->EXPASYNC) < 0) sys->fprint(stderr, "styxd: file export: %r\n"); } user(): string { sys = load Sys Sys->PATH; fd := sys->open("/dev/user", sys->OREAD); if(fd == nil){ sys->fprint(stderr, "styxd: can't open /dev/user: %r\n"); exit; } buf := array[128] of byte; n := sys->read(fd, buf, len buf); if(n < 0){ sys->fprint(stderr, "styxd: failed to read /dev/user: %r\n"); exit; } return string buf[0:n]; }