~ubuntu-branches/ubuntu/raring/gnupg2/raring

« back to all changes in this revision

Viewing changes to tools/watchgnupg.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2012-11-06 11:25:58 UTC
  • mfrom: (1.1.16) (7.1.8 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121106112558-lkpndvv4gqthgrn4
Tags: 2.0.19-1ubuntu1
* Resynchronize on Debian, remaining changes:
  - Add udev rules to give gpg access to some smartcard readers;
    Debian #543217.
    . debian/gnupg2.dev: udev rules to set ACLs on SCM smartcard readers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#define MYVERSION_LINE PGM " (GnuPG) " VERSION
41
41
#define BUGREPORT_LINE "\nReport bugs to <bug-gnupg@gnu.org>.\n"
42
42
#else
43
 
#define MYVERSION_LINE PGM 
 
43
#define MYVERSION_LINE PGM
44
44
#define BUGREPORT_LINE ""
45
45
#endif
46
46
#if !defined(SUN_LEN) || !defined(PF_LOCAL) || !defined(AF_LOCAL)
109
109
    die ("out of core");
110
110
  return p;
111
111
}
112
 
    
 
112
 
113
113
 
114
114
struct client_s {
115
115
  struct client_s *next;
117
117
  size_t size;  /* Allocated size of buffer. */
118
118
  size_t len;   /* Current length of buffer. */
119
119
  unsigned char *buffer; /* Buffer to with data already read. */
120
 
  
 
120
 
121
121
};
122
122
typedef struct client_s *client_t;
123
123
 
128
128
{
129
129
  struct tm *tp;
130
130
  time_t atime = time (NULL);
131
 
  
 
131
 
132
132
  tp = localtime (&atime);
133
133
  printf ("%3d - %04d-%02d-%02d %02d:%02d:%02d ",
134
134
          fd,
150
150
      if (c->buffer && c->len)
151
151
        {
152
152
          print_fd_and_time (c->fd);
153
 
          fwrite (c->buffer, c->len, 1, stdout); 
 
153
          fwrite (c->buffer, c->len, 1, stdout);
154
154
          putc ('\n', stdout);
155
155
          c->len = 0;
156
156
        }
162
162
      print_fd_and_time (c->fd);
163
163
      if (c->buffer && c->len)
164
164
        {
165
 
          fwrite (c->buffer, c->len, 1, stdout); 
 
165
          fwrite (c->buffer, c->len, 1, stdout);
166
166
          c->len = 0;
167
167
        }
168
 
      fwrite (line, s - line + 1, 1, stdout); 
 
168
      fwrite (line, s - line + 1, 1, stdout);
169
169
      line = s + 1;
170
170
    }
171
171
  n = strlen (line);
188
188
print_version (int with_help)
189
189
{
190
190
  fputs (MYVERSION_LINE "\n"
191
 
         "Copyright (C) 2004 Free Software Foundation, Inc.\n"
 
191
         "Copyright (C) 2012 Free Software Foundation, Inc.\n"
192
192
         "This program comes with ABSOLUTELY NO WARRANTY.\n"
193
193
         "This is free software, and you are welcome to redistribute it\n"
194
194
         "under certain conditions. See the file COPYING for details.\n",
195
195
         stdout);
196
 
        
 
196
 
197
197
  if (with_help)
198
198
    fputs ("\n"
199
199
          "Usage: " PGM " [OPTIONS] SOCKETNAME\n"
204
204
          "  --version   print version of the program and exit\n"
205
205
          "  --help      display this help and exit\n"
206
206
          BUGREPORT_LINE, stdout );
207
 
  
 
207
 
208
208
  exit (0);
209
209
}
210
210
 
211
 
int 
 
211
int
212
212
main (int argc, char **argv)
213
213
{
214
214
  int last_argc = -1;
219
219
  int server;
220
220
  int flags;
221
221
  client_t client_list = NULL;
222
 
 
 
222
 
223
223
  if (argc)
224
224
    {
225
225
      argc--; argv++;
246
246
          force = 1;
247
247
          argc--; argv++;
248
248
        }
249
 
    }          
250
 
 
 
249
    }
 
250
 
251
251
  if (argc != 1)
252
252
    {
253
253
      fprintf (stderr, "usage: " PGM " socketname\n");
272
272
    die ("fcntl (F_GETFL) failed: %s\n", strerror (errno));
273
273
  if ( fcntl (server, F_SETFL, (flags | O_NONBLOCK)) == -1)
274
274
    die ("fcntl (F_SETFL) failed: %s\n", strerror (errno));
275
 
  
 
275
 
276
276
 
277
277
  memset (&srvr_addr, 0, sizeof srvr_addr);
278
278
  srvr_addr.sun_family = AF_LOCAL;
280
280
  srvr_addr.sun_path[sizeof (srvr_addr.sun_path) - 1] = 0;
281
281
  addrlen = SUN_LEN (&srvr_addr);
282
282
 
283
 
  
 
283
 
284
284
 again:
285
285
  if (bind (server, (struct sockaddr *) &srvr_addr, addrlen))
286
 
    { 
 
286
    {
287
287
      if (errno == EADDRINUSE && force)
288
288
        {
289
289
          force = 0;
320
320
        continue;  /* Ignore any errors. */
321
321
 
322
322
      if (FD_ISSET (server, &rfds)) /* New connection. */
323
 
        { 
 
323
        {
324
324
          struct sockaddr_un clnt_addr;
325
325
          int fd;
326
326
 
335
335
              close (fd);
336
336
              printf ("[connection request denied: too many connections]\n");
337
337
            }
338
 
          else 
 
338
          else
339
339
            {
340
340
              for (client = client_list; client && client->fd != -1;
341
341
                   client = client->next)
355
355
          {
356
356
            char line[256];
357
357
            int n;
358
 
            
 
358
 
359
359
            n = read (client->fd, line, sizeof line - 1);
360
360
            if (n < 0)
361
361
              {
366
366
                close (client->fd);
367
367
                client->fd = -1;
368
368
              }
369
 
            else if (!n) 
 
369
            else if (!n)
370
370
              {
371
371
                print_line (client, NULL); /* flush */
372
372
                close (client->fd);