int vncsrvauth(Vnc *v) { Chalstate *c; AuthInfo *ai; if((c = auth_challenge("proto=vnc role=server user=%q", getuser()))==nil) sysfatal("vncchal: %r"); if(c->nchal != VncChalLen) sysfatal("vncchal got %d bytes wanted %d", c->nchal, VncChalLen); vncwrlong(v, AVncAuth); vncwrbytes(v, c->chal, VncChalLen); vncflush(v); vncrdbytes(v, c->chal, VncChalLen); c->resp = c->chal; c->nresp = VncChalLen; ai = auth_response(c); auth_freechal(c); if(ai == nil){ fprint(2, "vnc auth failed: server factotum: %r\n"); vncwrlong(v, VncAuthFailed); vncflush(v); return -1; } auth_freeAI(ai); vncwrlong(v, VncAuthOK); vncflush(v); return 0; }
void vncwrstring(Vnc *v, char *s) { ulong len; len = strlen(s); vncwrlong(v, len); vncwrbytes(v, s, len); }
void vncwrshort(Vnc *v, ushort u) { uchar buf[2]; buf[0] = u>>8; buf[1] = u; vncwrbytes(v, buf, 2); }
void vncwrshort(Vnc *v, uint16_t u) { uint8_t buf[2]; buf[0] = u>>8; buf[1] = u; vncwrbytes(v, buf, 2); }
void vncwrlong(Vnc *v, ulong u) { uchar buf[4]; buf[0] = u>>24; buf[1] = u>>16; buf[2] = u>>8; buf[3] = u; vncwrbytes(v, buf, 4); }
void vncwrlong(Vnc *v, uint32_t u) { uint8_t buf[4]; buf[0] = u>>24; buf[1] = u>>16; buf[2] = u>>8; buf[3] = u; vncwrbytes(v, buf, 4); }
void checksnarf(Vnc *v) { Dir *dir; char *snarf; int len; if(snarffd < 0) { snarffd = open("/dev/snarf", OREAD); if(snarffd < 0) sysfatal("can't open /dev/snarf: %r"); } for(;;) { sleep(1000); dir = dirstat("/dev/snarf"); if(dir == nil) /* this happens under old drawterm */ continue; if(dir->qid.vers > snarfvers) { snarf = getsnarf(&len); vnclock(v); vncwrchar(v, MCCut); vncwrbytes(v, "pad", 3); vncwrlong(v, len); vncwrbytes(v, snarf, len); vncflush(v); vncunlock(v); free(snarf); snarfvers = dir->qid.vers; } free(dir); } }
void vncwrpixfmt(Vnc *v, Pixfmt *fmt) { vncwrchar(v, fmt->bpp); vncwrchar(v, fmt->depth); vncwrchar(v, fmt->bigendian); vncwrchar(v, fmt->truecolor); vncwrshort(v, fmt->red.max); vncwrshort(v, fmt->green.max); vncwrshort(v, fmt->blue.max); vncwrchar(v, fmt->red.shift); vncwrchar(v, fmt->green.shift); vncwrchar(v, fmt->blue.shift); vncwrbytes(v, zero, 3); }
int vncsrvhandshake(Vnc *v) { char msg[VerLen+1]; strecpy(msg, msg+sizeof msg, version); if(verbose) fprint(2, "server version: %s", msg); vncwrbytes(v, msg, VerLen); vncflush(v); vncrdbytes(v, msg, VerLen); if(verbose) fprint(2, "client version: %s", msg); return 0; }
int vnchandshake(Vnc *v) { char msg[VerLen+1]; msg[VerLen] = 0; vncrdbytes(v, msg, VerLen); if(strncmp(msg, "RFB ", 4) != 0){ werrstr("bad rfb version \"%s\"", msg); return -1; } if(verbose) fprint(2, "server version: %s", msg); strcpy(msg, version); vncwrbytes(v, msg, VerLen); vncflush(v); return 0; }
int vncauth(Vnc *v, char *keypattern) { char pw[128], *reason; uint8_t chal[VncChalLen]; uint32_t auth; char *p, *server; if(keypattern == nil) keypattern = ""; auth = vncrdlong(v); switch(auth){ default: werrstr("unknown auth type 0x%lux", auth); if(verbose) fprint(2, "unknown auth type 0x%lux", auth); return -1; case AFailed: reason = vncrdstring(v); werrstr("%s", reason); if(verbose) fprint(2, "auth failed: %s\n", reason); return -1; case ANoAuth: if(verbose) fprint(2, "no auth needed"); break; case AVncAuth: vncrdbytes(v, chal, VncChalLen); server = strdup(serveraddr); p = strrchr(server, ':'); if(p) *p = 0; if(auth_respond(chal, VncChalLen, nil, 0, chal, VncChalLen, auth_getkey, "proto=vnc role=client server=%s %s", server, keypattern) != VncChalLen){ /* BUG This is for drawterm users who don't start their own factotums */ readln("password: "******"unknown server response 0x%lux", auth); return -1; case VncAuthFailed: werrstr("server says authentication failed"); return -1; case VncAuthTooMany: werrstr("server says too many tries"); return -1; case VncAuthOK: break; } break; } return 0; }
void vncwrchar(Vnc *v, uchar c) { vncwrbytes(v, &c, 1); }
void vncwrchar(Vnc *v, uint8_t c) { vncwrbytes(v, &c, 1); }