1
/* -*-mode:java; c-basic-offset:2; -*- */
1
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
3
Copyright (c) 2002,2003,2004 ymnk, JCraft,Inc. All rights reserved.
3
Copyright (c) 2002,2003,2004,2005,2006 ymnk, JCraft,Inc. All rights reserved.
5
5
Redistribution and use in source and binary forms, with or without
6
6
modification, are permitted provided that the following conditions are met:
86
86
if(j==-1){ break loop;}
87
87
if(j==0x0d){ continue; }
88
88
if(j==0x0a){ break; }
90
if(bufl>1024*10) break; // too long...
91
byte[] newbuf=new byte[buf.length*2];
92
System.arraycopy(buf, 0, newbuf, 0, buf.length);
89
95
buf[bufl++]=(byte)j;
192
201
//System.out.println("fail!!");
195
204
public void add(String host, byte[] key, UserInfo userinfo){
197
206
int type=getType(key);
198
for(int i=0; i<pool.size(); i++){
199
hk=(HostKey)(pool.elementAt(i));
200
if(isIncluded(hk.host, host) && hk.type==type){
209
for(int i=0; i<pool.size(); i++){
210
hk=(HostKey)(pool.elementAt(i));
211
if(isIncluded(hk.host, host) && hk.type==type){
202
if(Util.array_equals(hk.key, key)){ return; }
203
if(hk.host.equals(host)){
208
hk.host=deleteSubString(hk.host, host);
213
if(Util.array_equals(hk.key, key)){ return; }
214
if(hk.host.equals(host)){
219
hk.host=deleteSubString(hk.host, host);
214
227
hk=new HostKey(host, type, key);
215
228
pool.addElement(hk);
217
230
String bar=getKnownHostsRepositoryID();
220
232
boolean foo=true;
221
233
File goo=new File(bar);
222
234
if(!goo.exists()){
225
foo=userinfo.promptYesNo(
226
bar+" does not exist.\n"+
227
"Are you sure you want to create it?"
229
goo=goo.getParentFile();
230
if(foo && goo!=null && !goo.exists()){
231
foo=userinfo.promptYesNo(
232
"The parent directory "+goo+" does not exist.\n"+
233
"Are you sure you want to create it?"
237
userinfo.showMessage(goo+" has not been created.");
241
userinfo.showMessage(goo+" has been succesfully created.\nPlease check its access permission.");
245
if(goo==null)foo=false;
237
foo=userinfo.promptYesNo(bar+" does not exist.\n"+
238
"Are you sure you want to create it?"
240
goo=goo.getParentFile();
241
if(foo && goo!=null && !goo.exists()){
242
foo=userinfo.promptYesNo("The parent directory "+goo+" does not exist.\n"+
243
"Are you sure you want to create it?"
247
userinfo.showMessage(goo+" has not been created.");
251
userinfo.showMessage(goo+" has been succesfully created.\nPlease check its access permission.");
255
if(goo==null)foo=false;
252
catch(Exception e){ System.out.println("sync known_hosts: "+e); }
262
catch(Exception e){ System.out.println("sync known_hosts: "+e); }
290
300
public void remove(String host, String type, byte[] key){
291
301
boolean sync=false;
292
303
for(int i=0; i<pool.size(); i++){
293
304
HostKey hk=(HostKey)(pool.elementAt(i));
305
String hosts=hk.getHost();
295
(hk.getHost().equals(host) &&
307
(isIncluded(hosts, host) &&
296
308
(type==null || (hk.getType().equals(type) &&
297
309
(key==null || Util.array_equals(key, hk.key)))))){
298
pool.removeElement(hk);
310
if(hosts.equals(host)){
311
pool.removeElement(hk);
314
hk.host=deleteSubString(hosts, host);
303
321
try{sync();}catch(Exception e){};
307
private void sync() throws IOException {
325
protected void sync() throws IOException {
308
326
if(known_hosts!=null)
309
327
sync(known_hosts);
311
private void sync(String foo) throws IOException {
329
protected synchronized void sync(String foo) throws IOException {
312
330
if(foo==null) return;
313
331
FileOutputStream fos=new FileOutputStream(foo);