~jr/ubuntu/oneiric/apt/bzr-get-rename

« back to all changes in this revision

Viewing changes to methods/rsh.cc

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2005-03-07 20:08:33 UTC
  • Revision ID: james.westby@ubuntu.com-20050307200833-0lxdgg2cb4oculdv
Tags: 0.6.35
* Merge apt--mvo--0 (incorporates 0.6.34ubuntu1):
  - Implement MaxSize and MaxAge in apt.cron.daily, to prevent the cache
    from growing too large (Ubuntu #6761)
  - some comments about the pkgAcqMetaSig::Custom600Headers() added
  - use gpg --with-colons
  - commented the ftp no_proxy unseting in methods/ftp.cc
  - added support for "Acquire::gpgv::options" in methods/gpgv.cc
* Merge bubulle@debian.org--2005/apt--main--0
  - Make capitalization more consistent
  - Un-fuzzy translations resulting from capitalization changes
  - Italian translation update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- mode: cpp; mode: fold -*-
2
2
// Description                                                          /*{{{*/
3
 
// $Id: rsh.cc,v 1.4 2001/03/13 06:51:46 jgg Exp $
 
3
// $Id: rsh.cc,v 1.6.2.1 2004/01/16 18:58:50 mdz Exp $
4
4
/* ######################################################################
5
5
 
6
6
   RSH method - Transfer files via rsh compatible program
10
10
 
11
11
   ##################################################################### */
12
12
                                                                        /*}}}*/
13
 
// Iclude Files                                                         /*{{{*/
 
13
// Include Files                                                        /*{{{*/
14
14
#include "rsh.h"
15
15
#include <apt-pkg/error.h>
16
16
 
22
22
#include <stdio.h>
23
23
#include <errno.h>
24
24
#include <stdarg.h>
 
25
#include <apti18n.h>
25
26
                                                                        /*}}}*/
26
27
 
27
28
const char *Prog;
28
29
unsigned long TimeOut = 120;
 
30
Configuration::Item const *RshOptions = 0;
29
31
time_t RSHMethod::FailTime = 0;
30
32
string RSHMethod::FailFile;
31
33
int RSHMethod::FailFd = -1;
86
88
   int Pipes[4] = {-1,-1,-1,-1};
87
89
   if (pipe(Pipes) != 0 || pipe(Pipes+2) != 0)
88
90
   {
89
 
      _error->Errno("pipe","Failed to create IPC pipe to subprocess");
 
91
      _error->Errno("pipe",_("Failed to create IPC pipe to subprocess"));
90
92
      for (int I = 0; I != 4; I++)
91
93
         close(Pipes[I]);
92
94
      return false;
99
101
   // The child
100
102
   if (Process == 0)
101
103
   {
102
 
      const char *Args[6];
103
 
      int i = 0;
 
104
      const char *Args[400];
 
105
      unsigned int i = 0;
104
106
 
105
107
      dup2(Pipes[1],STDOUT_FILENO);
106
108
      dup2(Pipes[2],STDIN_FILENO);
108
110
      // Probably should do
109
111
      // dup2(open("/dev/null",O_RDONLY),STDERR_FILENO);
110
112
 
 
113
      // Insert user-supplied command line options
 
114
      Configuration::Item const *Opts = RshOptions;
 
115
      if (Opts != 0)
 
116
      {
 
117
         Opts = Opts->Child;
 
118
         for (; Opts != 0; Opts = Opts->Next)
 
119
         {
 
120
            if (Opts->Value.empty() == true)
 
121
               continue;
 
122
            Args[i++] = Opts->Value.c_str();
 
123
         }
 
124
      }
 
125
 
111
126
      Args[i++] = Prog;
112
127
      if (User.empty() == false) {
113
128
         Args[i++] = "-l";
165
180
      if (WaitFd(ReadFd,false,TimeOut) == false)
166
181
      {
167
182
         Close();
168
 
         return _error->Error("Connection timeout");
 
183
         return _error->Error(_("Connection timeout"));
169
184
      }
170
185
 
171
186
      // Suck it back
172
187
      int Res = read(ReadFd,Buffer + Len,sizeof(Buffer) - Len);
173
188
      if (Res <= 0)
174
189
      {
175
 
         _error->Errno("read","Read error");
 
190
         _error->Errno("read",_("Read error"));
176
191
         Close();
177
192
         return false;
178
193
      }
179
194
      Len += Res;
180
195
   }
181
196
 
182
 
   return _error->Error("A response overflowed the buffer.");
 
197
   return _error->Error(_("A response overflowed the buffer."));
183
198
}
184
199
                                                                        /*}}}*/
185
200
// RSHConn::WriteMsg - Send a message with optional remote sync.        /*{{{*/
208
223
      {
209
224
         
210
225
         Close();
211
 
         return _error->Error("Connection timeout");
 
226
         return _error->Error(_("Connection timeout"));
212
227
      }      
213
228
      
214
229
      int Res = write(WriteFd,S + Start,Len);
215
230
      if (Res <= 0)
216
231
      {
217
 
         _error->Errno("write","Write Error");
 
232
         _error->Errno("write",_("Write error"));
218
233
         Close();
219
234
         return false;
220
235
      }
246
261
   char *End;
247
262
   Size = strtoul(Msg.c_str(),&End,10);
248
263
   if (End == Msg.c_str())
249
 
      return _error->Error("File Not Found");
 
264
      return _error->Error(_("File not found"));
250
265
   return true;
251
266
}
252
267
                                                                        /*}}}*/
285
300
 
286
301
   if (Resume != 0) {
287
302
      if (Hash.AddFD(To.Fd(),Resume) == false) {
288
 
         _error->Errno("read","Problem hashing file");
 
303
         _error->Errno("read",_("Problem hashing file"));
289
304
         return false;
290
305
      }
291
306
   }
304
319
      if (WaitFd(ReadFd,false,TimeOut) == false)
305
320
      {
306
321
         Close();
307
 
         return _error->Error("Data socket timed out");
 
322
         return _error->Error(_("Data socket timed out"));
308
323
      }
309
324
 
310
325
      // Read the data..
312
327
      if (Res == 0)
313
328
      {
314
329
         Close();
315
 
         return _error->Error("Connection closed prematurely");
 
330
         return _error->Error(_("Connection closed prematurely"));
316
331
      }
317
332
      
318
333
      if (Res < 0)
338
353
// RSHMethod::RSHMethod - Constructor                                   /*{{{*/
339
354
// ---------------------------------------------------------------------
340
355
/* */
341
 
RSHMethod::RSHMethod() : pkgAcqMethod("1.0")
 
356
RSHMethod::RSHMethod() : pkgAcqMethod("1.0",SendConfig)
342
357
{
343
358
   signal(SIGTERM,SigTerm);
344
359
   signal(SIGINT,SigTerm);
346
361
   FailFd = -1;
347
362
};
348
363
                                                                        /*}}}*/
 
364
// RSHMethod::Configuration - Handle a configuration message            /*{{{*/
 
365
// ---------------------------------------------------------------------
 
366
bool RSHMethod::Configuration(string Message)
 
367
{
 
368
   char ProgStr[100];
 
369
  
 
370
   if (pkgAcqMethod::Configuration(Message) == false)
 
371
      return false;
 
372
 
 
373
   snprintf(ProgStr, sizeof ProgStr, "Acquire::%s::Timeout", Prog);
 
374
   TimeOut = _config->FindI(ProgStr,TimeOut);
 
375
   snprintf(ProgStr, sizeof ProgStr, "Acquire::%s::Options", Prog);
 
376
   RshOptions = _config->Tree(ProgStr);
 
377
 
 
378
   return true;
 
379
}
 
380
                                                                        /*}}}*/
349
381
// RSHMethod::SigTerm - Clean up and timestamp the files on exit        /*{{{*/
350
382
// ---------------------------------------------------------------------
351
383
/* */
390
422
 
391
423
   // We say this mainly because the pause here is for the
392
424
   // ssh connection that is still going
393
 
   Status("Connecting to %s", Get.Host.c_str());
 
425
   Status(_("Connecting to %s"), Get.Host.c_str());
394
426
 
395
427
   // Get the files information
396
428
   unsigned long Size;
398
430
       Server->ModTime(File,FailTime) == false)
399
431
   {
400
432
      //Fail(true);
401
 
      //_error->Error("File Not Found"); // Will be handled by Size
 
433
      //_error->Error(_("File not found")); // Will be handled by Size
402
434
      return false;
403
435
   }
404
436
   Res.Size = Size;
479
511
 
480
512
int main(int argc, const char *argv[])
481
513
{
 
514
   setlocale(LC_ALL, "");
 
515
 
482
516
   RSHMethod Mth;
483
517
   Prog = strrchr(argv[0],'/');
484
518
   Prog++;