|
@@ -24,6 +24,7 @@
|
|
|
#include <algorithm>
|
|
|
#include "app.h"
|
|
|
#include "numlock.h"
|
|
|
+#include "util.h"
|
|
|
|
|
|
|
|
|
#ifdef HAVE_SHADOW
|
|
@@ -128,15 +129,18 @@ void User1Signal(int sig) {
|
|
|
|
|
|
|
|
|
#ifdef USE_PAM
|
|
|
-App::App(int argc, char** argv):
|
|
|
- pam(conv, static_cast<void*>(&LoginPanel)){
|
|
|
+App::App(int argc, char** argv)
|
|
|
+ : pam(conv, static_cast<void*>(&LoginPanel)),
|
|
|
#else
|
|
|
-App::App(int argc, char** argv){
|
|
|
+App::App(int argc, char** argv)
|
|
|
+ :
|
|
|
#endif
|
|
|
+ mcookiesize(32) // Must be divisible by 4
|
|
|
+{
|
|
|
int tmp;
|
|
|
ServerPID = -1;
|
|
|
testing = false;
|
|
|
- mcookie = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
|
|
+ mcookie = string(App::mcookiesize, 'a');
|
|
|
daemonmode = false;
|
|
|
force_nodaemon = false;
|
|
|
firstlogin = true;
|
|
@@ -1127,13 +1131,13 @@ string App::findValidRandomTheme(const string& set)
|
|
|
name = name.substr(0, name.length() - 1);
|
|
|
}
|
|
|
|
|
|
- srandom(getpid()+time(NULL));
|
|
|
+ Util::srandom(Util::makeseed());
|
|
|
|
|
|
vector<string> themes;
|
|
|
string themefile;
|
|
|
Cfg::split(themes, name, ',');
|
|
|
do {
|
|
|
- int sel = random() % themes.size();
|
|
|
+ int sel = Util::random() % themes.size();
|
|
|
|
|
|
name = Cfg::Trim(themes[sel]);
|
|
|
themefile = string(THEMESDIR) +"/" + name + THEMESFILE;
|
|
@@ -1160,33 +1164,33 @@ void App::replaceVariables(string& input,
|
|
|
}
|
|
|
|
|
|
|
|
|
+/*
|
|
|
+ * We rely on the fact that all bits generated by Util::random()
|
|
|
+ * are usable, so we are taking full words from its output.
|
|
|
+ */
|
|
|
void App::CreateServerAuth() {
|
|
|
/* create mit cookie */
|
|
|
- int i, r;
|
|
|
- int hexcount = 0;
|
|
|
- string authfile;
|
|
|
- string cmd;
|
|
|
+ uint16_t word;
|
|
|
+ uint8_t hi, lo;
|
|
|
+ int i;
|
|
|
+ string authfile;
|
|
|
const char *digits = "0123456789abcdef";
|
|
|
- srand( time(NULL) );
|
|
|
- for ( i = 0; i < 31; i++ ) {
|
|
|
- r = rand()%16;
|
|
|
- mcookie[i] = digits[r];
|
|
|
- if (r>9)
|
|
|
- hexcount++;
|
|
|
+ Util::srandom(Util::makeseed());
|
|
|
+ for (i = 0; i < App::mcookiesize; i+=4) {
|
|
|
+ word = Util::random() & 0xffff;
|
|
|
+ lo = word & 0xff;
|
|
|
+ hi = word >> 8;
|
|
|
+ mcookie[i] = digits[lo & 0x0f];
|
|
|
+ mcookie[i+1] = digits[lo >> 4];
|
|
|
+ mcookie[i+2] = digits[hi & 0x0f];
|
|
|
+ mcookie[i+3] = digits[hi >> 4];
|
|
|
}
|
|
|
- /* MIT-COOKIE: even occurrences of digits and hex digits */
|
|
|
- if ((hexcount%2) == 0) {
|
|
|
- r = rand()%10;
|
|
|
- } else {
|
|
|
- r = rand()%5+10;
|
|
|
- }
|
|
|
- mcookie[31] = digits[r];
|
|
|
/* reinitialize auth file */
|
|
|
authfile = cfg->getOption("authfile");
|
|
|
remove(authfile.c_str());
|
|
|
putenv(StrConcat("XAUTHORITY=", authfile.c_str()));
|
|
|
- cmd = cfg->getOption("xauth_path") + " -q -f " + authfile + " add :0 . " + mcookie;
|
|
|
- system(cmd.c_str());
|
|
|
+ Util::add_mcookie(mcookie, ":0", cfg->getOption("xauth_path"),
|
|
|
+ authfile);
|
|
|
}
|
|
|
|
|
|
char* App::StrConcat(const char* str1, const char* str2) {
|