~ubuntu-branches/ubuntu/jaunty/gnupg2/jaunty-security

« back to all changes in this revision

Viewing changes to g10/photoid.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* photoid.c - photo ID handling code
2
 
 * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
 
2
 * Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of GnuPG.
5
5
 *
6
6
 * GnuPG is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * the Free Software Foundation; either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
11
 * GnuPG is distributed in the hope that it will be useful,
14
14
 * GNU General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
20
#include <config.h>
28
27
#  define VER_PLATFORM_WIN32_WINDOWS 1
29
28
# endif
30
29
#endif
 
30
 
 
31
#include "gpg.h"
31
32
#include "packet.h"
32
33
#include "status.h"
33
34
#include "exec.h"
35
36
#include "util.h"
36
37
#include "i18n.h"
37
38
#include "iobuf.h"
38
 
#include "memory.h"
39
39
#include "options.h"
40
40
#include "main.h"
41
41
#include "photoid.h"
 
42
#include "ttyio.h"
42
43
 
43
44
/* Generate a new photo id packet, or return NULL if canceled */
44
 
PKT_user_id *generate_photo_id(PKT_public_key *pk)
 
45
PKT_user_id *
 
46
generate_photo_id(PKT_public_key *pk,const char *photo_name)
45
47
{
46
48
  PKT_user_id *uid;
47
49
  int error=1,i;
48
50
  unsigned int len;
49
 
  char *filename=NULL;
 
51
  char *filename;
50
52
  byte *photo=NULL;
51
53
  byte header[16];
52
 
  iobuf_t file;
 
54
  IOBUF file;
 
55
  int overflow;
53
56
 
54
57
  header[0]=0x10; /* little side of photo header length */
55
58
  header[1]=0;    /* big side of photo header length */
60
63
    header[i]=0;
61
64
 
62
65
#define EXTRA_UID_NAME_SPACE 71
63
 
  uid=xcalloc (1,sizeof(*uid)+71);
 
66
  uid=xmalloc_clear(sizeof(*uid)+71);
64
67
 
65
 
  printf(_("\nPick an image to use for your photo ID.  "
66
 
           "The image must be a JPEG file.\n"
67
 
           "Remember that the image is stored within your public key.  "
68
 
           "If you use a\n"
69
 
           "very large picture, your key will become very large as well!\n"
70
 
           "Keeping the image close to 240x288 is a good size to use.\n"));
 
68
  if(photo_name && *photo_name)
 
69
    filename=make_filename(photo_name,(void *)NULL);
 
70
  else
 
71
    {
 
72
      tty_printf(_("\nPick an image to use for your photo ID."
 
73
                   "  The image must be a JPEG file.\n"
 
74
                   "Remember that the image is stored within your public key."
 
75
                   "  If you use a\n"
 
76
                   "very large picture, your key will become very large"
 
77
                   " as well!\n"
 
78
                   "Keeping the image close to 240x288 is a good size"
 
79
                   " to use.\n"));
 
80
      filename=NULL;
 
81
    }
71
82
 
72
83
  while(photo==NULL)
73
84
    {
74
 
      printf("\n");
75
 
 
76
 
      xfree (filename);
77
 
 
78
 
      filename=cpr_get("photoid.jpeg.add",
79
 
                       _("Enter JPEG filename for photo ID: "));
80
 
 
81
 
      if(strlen(filename)==0)
82
 
        goto scram;
 
85
      if(filename==NULL)
 
86
        {
 
87
          char *tempname;
 
88
 
 
89
          tty_printf("\n");
 
90
 
 
91
          tty_enable_completion(NULL);
 
92
 
 
93
          tempname=cpr_get("photoid.jpeg.add",
 
94
                           _("Enter JPEG filename for photo ID: "));
 
95
 
 
96
          tty_disable_completion();
 
97
 
 
98
          filename=make_filename(tempname,(void *)NULL);
 
99
 
 
100
          xfree(tempname);
 
101
 
 
102
          if(strlen(filename)==0)
 
103
            goto scram;
 
104
        }
83
105
 
84
106
      file=iobuf_open(filename);
 
107
      if (file && is_secured_file (iobuf_get_fd (file)))
 
108
        {
 
109
          iobuf_close (file);
 
110
          file = NULL;
 
111
          errno = EPERM;
 
112
        }
85
113
      if(!file)
86
114
        {
87
 
          log_error(_("Unable to open photo \"%s\": %s\n"),
 
115
          log_error(_("unable to open JPEG file `%s': %s\n"),
88
116
                    filename,strerror(errno));
 
117
          xfree(filename);
 
118
          filename=NULL;
89
119
          continue;
90
120
        }
91
121
 
92
 
      len=iobuf_get_filelength(file);
93
 
      if(len>6144)
 
122
      
 
123
      len=iobuf_get_filelength(file, &overflow);
 
124
      if(len>6144 || overflow)
94
125
        {
95
 
          printf("This JPEG is really large (%d bytes) !\n",len);
 
126
          tty_printf( _("This JPEG is really large (%d bytes) !\n"),len);
96
127
          if(!cpr_get_answer_is_yes("photoid.jpeg.size",
97
 
                            _("Are you sure you want to use it (y/N)? ")))
 
128
                            _("Are you sure you want to use it? (y/N) ")))
98
129
          {
99
130
            iobuf_close(file);
 
131
            xfree(filename);
 
132
            filename=NULL;
100
133
            continue;
101
134
          }
102
135
        }
103
136
 
104
 
      photo=xmalloc (len);
 
137
      photo=xmalloc(len);
105
138
      iobuf_read(file,photo,len);
106
139
      iobuf_close(file);
107
140
 
109
142
      if(photo[0]!=0xFF || photo[1]!=0xD8 ||
110
143
         photo[6]!='J' || photo[7]!='F' || photo[8]!='I' || photo[9]!='F')
111
144
        {
112
 
          log_error(_("\"%s\" is not a JPEG file\n"),filename);
113
 
          xfree (photo);
 
145
          log_error(_("`%s' is not a JPEG file\n"),filename);
 
146
          xfree(photo);
114
147
          photo=NULL;
 
148
          xfree(filename);
 
149
          filename=NULL;
115
150
          continue;
116
151
        }
117
152
 
132
167
              goto scram;
133
168
            case 0:
134
169
              free_attributes(uid);
135
 
              xfree (photo);
 
170
              xfree(photo);
136
171
              photo=NULL;
 
172
              xfree(filename);
 
173
              filename=NULL;
137
174
              continue;
138
175
            }
139
176
        }
143
180
  uid->ref=1;
144
181
 
145
182
 scram:
146
 
  xfree (filename);
147
 
  xfree (photo);
 
183
  xfree(filename);
 
184
  xfree(photo);
148
185
 
149
186
  if(error)
150
187
    {
151
188
      free_attributes(uid);
152
 
      xfree (uid);
 
189
      xfree(uid);
153
190
      return NULL;
154
191
    }
155
192
 
283
320
        if(!command)
284
321
          goto fail;
285
322
 
286
 
        name=xmalloc (16+strlen(EXTSEP_S)+
 
323
        name=xmalloc(16+strlen(EXTSEP_S)+
287
324
                     strlen(image_type_to_string(args.imagetype,0))+1);
288
325
 
289
326
        /* Make the filename.  Notice we are not using the image
302
339
 
303
340
        if(exec_write(&spawn,NULL,command,name,1,1)!=0)
304
341
          {
305
 
            xfree (name);
 
342
            xfree(name);
306
343
            goto fail;
307
344
          }
308
345
 
311
348
                                        image_type_to_string(args.imagetype,2));
312
349
#endif
313
350
 
314
 
        xfree (name);
 
351
        xfree(name);
315
352
 
316
353
        fwrite(&attrs[i].data[offset],attrs[i].len-offset,1,spawn->tochild);
317
354