static Bool AuthenticateVNC(void) { CARD32 authScheme, authResult; CARD8 challenge[CHALLENGESIZE]; char *passwd; char buffer[64]; char* cstatus; int len; fprintf(stderr, "Performing standard VNC authentication\n"); if (!ReadFromRFBServer((char *)challenge, CHALLENGESIZE)) return False; if (appData.passwordFile) { passwd = vncDecryptPasswdFromFile(appData.passwordFile); if (!passwd) { fprintf(stderr, "Cannot read valid password from file \"%s\"\n", appData.passwordFile); return False; } } else if (appData.autoPass) { passwd = buffer; cstatus = fgets(buffer, sizeof buffer, stdin); if (cstatus == NULL) buffer[0] = '\0'; else { len = strlen(buffer); if (len > 0 && buffer[len - 1] == '\n') buffer[len - 1] = '\0'; } } else if (appData.passwordDialog) { passwd = DoPasswordDialog(); } else { passwd = getpass("Password: "******"Reading password failed\n"); return False; } if (strlen(passwd) > 8) { passwd[8] = '\0'; } vncEncryptBytes(challenge, passwd); /* Lose the password from memory */ memset(passwd, '\0', strlen(passwd)); if (!WriteExact(rfbsock, (char *)challenge, CHALLENGESIZE)) return False; if (!ReadFromRFBServer((char *)&authResult, 4)) return False; authResult = Swap32IfLE(authResult); switch (authResult) { case rfbVncAuthOK: fprintf(stderr, "VNC authentication succeeded\n"); break; case rfbVncAuthFailed: fprintf(stderr, "VNC authentication failed\n"); return False; case rfbVncAuthTooMany: fprintf(stderr, "VNC authentication failed - too many tries\n"); return False; default: fprintf(stderr, "Unknown VNC authentication result: %d\n", (int)authResult); return False; } return True; }
static Bool AuthenticateUnixLogin(void) { CARD32 loginLen, passwdLen, authResult; char *login; char *passwd; struct passwd *ps; fprintf(stderr, "Performing Unix login-style authentication\n"); if (appData.userLogin) { login = appData.userLogin; } else { ps = getpwuid(getuid()); login = ps->pw_name; } fprintf(stderr, "Using user name \"%s\"\n", login); if (appData.passwordDialog) { passwd = DoPasswordDialog(); } else { passwd = getpass("Password: "******"Reading password failed\n"); return False; } loginLen = Swap32IfLE((CARD32)strlen(login)); passwdLen = Swap32IfLE((CARD32)strlen(passwd)); if (!WriteExact(rfbsock, (char *)&loginLen, sizeof(loginLen)) || !WriteExact(rfbsock, (char *)&passwdLen, sizeof(passwdLen))) return False; if (!WriteExact(rfbsock, login, strlen(login)) || !WriteExact(rfbsock, passwd, strlen(passwd))) return False; /* Lose the password from memory */ memset(passwd, '\0', strlen(passwd)); if (!ReadFromRFBServer((char *)&authResult, sizeof(authResult))) return False; authResult = Swap32IfLE(authResult); switch (authResult) { case rfbVncAuthOK: fprintf(stderr, "Authentication succeeded\n"); break; case rfbVncAuthFailed: fprintf(stderr, "Authentication failed\n"); return False; case rfbVncAuthTooMany: fprintf(stderr, "Authentication failed - too many tries\n"); return False; default: fprintf(stderr, "Unknown authentication result: %d\n", (int)authResult); return False; } return True; }
static Bool AuthenticateVNC(void) { CARD32 authScheme; CARD8 challenge[CHALLENGESIZE]; char *passwd; char buffer[64]; char* cstatus; int len; if (!appData.ffInfo) { fprintf(stderr, "Performing standard VNC authentication\n"); } if (!ReadFromRFBServer((char *)challenge, CHALLENGESIZE)) return False; if (appData.play || appData.movie) { passwd = strdup ("dummy"); return ReadAuthenticationResult(); } if (appData.passwordFile) { passwd = vncDecryptPasswdFromFile(appData.passwordFile); if (!passwd) { fprintf(stderr, "Cannot read valid password from file \"%s\"\n", appData.passwordFile); return False; } } else if (appData.autoPass) { passwd = buffer; cstatus = fgets(buffer, sizeof buffer, stdin); if (cstatus == NULL) buffer[0] = '\0'; else { len = strlen(buffer); if (len > 0 && buffer[len - 1] == '\n') buffer[len - 1] = '\0'; } } else if (appData.passwordDialog) { passwd = DoPasswordDialog(); } else { passwd = getpass("Password: "******"Reading password failed\n"); return False; } if (strlen(passwd) > 8) { passwd[8] = '\0'; } vncEncryptBytes(challenge, passwd); /* Lose the password from memory */ memset(passwd, '\0', strlen(passwd)); if (!WriteExact(rfbsock, (char *)challenge, CHALLENGESIZE)) return False; return ReadAuthenticationResult(); }