13 |
|
configurate(); |
14 |
|
} |
15 |
|
|
16 |
+ |
string Configurator::password(const string& user) |
17 |
+ |
{ |
18 |
+ |
string password; |
19 |
+ |
|
20 |
+ |
for (unsigned index = 0; index < passwd.size(); index++) |
21 |
+ |
{ |
22 |
+ |
switch (passwd[index]) |
23 |
+ |
{ |
24 |
+ |
case file: |
25 |
+ |
{ |
26 |
+ |
string file = config.install + "/conf/private/" + host + "." |
27 |
+ |
+ user; |
28 |
+ |
ifstream fin(file.c_str()); |
29 |
+ |
|
30 |
+ |
if (fin.is_open()) |
31 |
+ |
{ |
32 |
+ |
getline(fin, password); |
33 |
+ |
} |
34 |
+ |
} |
35 |
+ |
break; |
36 |
+ |
case prompt: |
37 |
+ |
{ |
38 |
+ |
string prompt = user + "@" + host + "\'s password:"; |
39 |
+ |
password = getpass(prompt.c_str()); |
40 |
+ |
} |
41 |
+ |
break; |
42 |
+ |
default: |
43 |
+ |
// |
44 |
+ |
break; |
45 |
+ |
} |
46 |
+ |
|
47 |
+ |
if (password == "") |
48 |
+ |
{ |
49 |
+ |
continue; |
50 |
+ |
} |
51 |
+ |
else |
52 |
+ |
{ |
53 |
+ |
break; |
54 |
+ |
} |
55 |
+ |
} |
56 |
+ |
|
57 |
+ |
return password; |
58 |
+ |
} |
59 |
+ |
|
60 |
|
void Configurator::configurate() |
61 |
|
{ |
62 |
|
if (config.hosts.count(host) < 2) |
63 |
|
{ |
64 |
< |
cerr << program << ": No configuration for host: " << host << "\n"; |
64 |
> |
cerr << program << ": " << host << ": No configuration\n"; |
65 |
|
exit(1); |
66 |
|
} |
67 |
|
|
121 |
|
} |
122 |
|
else |
123 |
|
{ |
124 |
< |
cerr << program << ": Unknown configuration entry: \"" << entry |
81 |
< |
<< "\", ignored\n"; |
124 |
> |
cerr << program << ": " << entry << ": Unknown configuration\n"; |
125 |
|
} |
126 |
|
} |
127 |
+ |
|
128 |
+ |
if (passwd.size() == 0) |
129 |
+ |
{ |
130 |
+ |
cerr << program << ": " << host << ": No passwd configuration\n"; |
131 |
+ |
exit(1); |
132 |
+ |
} |
133 |
+ |
|
134 |
+ |
if (regular.local == "" || regular.remote == "") |
135 |
+ |
{ |
136 |
+ |
cerr << program << ": " << host << ": No * folder configuration\n"; |
137 |
+ |
exit(1); |
138 |
+ |
} |
139 |
+ |
|
140 |
+ |
if (debug) |
141 |
+ |
{ |
142 |
+ |
cerr << "host = " << host << "\n" |
143 |
+ |
<< "passwd = {\n"; |
144 |
+ |
|
145 |
+ |
for (unsigned index = 0; index < passwd.size(); index++) |
146 |
+ |
{ |
147 |
+ |
cerr << " [" << index << "] = "; |
148 |
+ |
|
149 |
+ |
switch (passwd[index]) |
150 |
+ |
{ |
151 |
+ |
case file: |
152 |
+ |
cerr << "file"; |
153 |
+ |
break; |
154 |
+ |
case prompt: |
155 |
+ |
cerr << "prompt"; |
156 |
+ |
break; |
157 |
+ |
default: |
158 |
+ |
cerr << passwd[index]; |
159 |
+ |
break; |
160 |
+ |
} |
161 |
+ |
|
162 |
+ |
cerr << "\n"; |
163 |
+ |
} |
164 |
+ |
|
165 |
+ |
cerr << "}\n" |
166 |
+ |
<< "regular = {\n" |
167 |
+ |
<< " local = " << regular.local << "\n" |
168 |
+ |
<< " remote = " << regular.remote << "\n" |
169 |
+ |
<< "}\n" |
170 |
+ |
<< "folders = {\n"; |
171 |
+ |
|
172 |
+ |
for (map<string, Folder>::iterator itor = folders.begin(); itor != |
173 |
+ |
folders.end(); itor++) |
174 |
+ |
{ |
175 |
+ |
cerr << " " << itor->first << " = {\n" |
176 |
+ |
<< " local = " << itor->second.local << "\n" |
177 |
+ |
<< " remote = " << itor->second.remote << "\n" |
178 |
+ |
<< " }\n"; |
179 |
+ |
} |
180 |
+ |
|
181 |
+ |
cerr << "}\n"; |
182 |
+ |
} |
183 |
|
} |