/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-keygen

  • Committer: Teddy Hogeborn
  • Date: 2014-03-06 02:26:04 UTC
  • Revision ID: teddy@recompile.se-20140306022604-4uc43taz25cflgi3
Bug fix: Free all memory and give better messages when memory is full.

* plugin-runner.c (add_to_char_array): Bug fix: If realloc fails, do
                                       not change old array pointer.
  (add_environment): Bug fix: If realloc fails, do not change old
                     environment pointer.  Also rename "e" to "envdef"
                     for clarity.
  (main): Bug fix: If realloc fails, do not change old pointers.  Also
          wrap "#pragma GCC" with "#ifdef ___GNUC___".
* plugins.d/mandos-client.c (incbuffer): Bug fix: if realloc fails,
                                         free old buffer.
  (run_network_hooks): Moved variables "directory" and "ret" to their
                       innermost possible scope.
  (take_down_interface): Moved variables "sd", "ret_errno", and
                         "ret_setflags" to their innermost possible
                         scope.
  (main): Removed variable "interfaces_hooks_size".  Also, if argz_add
          fails when adding all found interfaces, the error message
          will now be correct.  Also print error message if, after
          having taken up an interface, argz_add fails to add
          interface to list of interfaces to be taken down.
* plugins.d/mandos-client.xml (OPTIONS): Explain better what "none"
                                         means as argument to
                                         "--interface" by negating
                                         sense.
* plugins.d/password-prompt.c (fprintf_plus): Removed (unused).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
3
3
# Mandos key generator - create a new OpenPGP key for a Mandos client
4
4
5
 
# Copyright © 2008-2014 Teddy Hogeborn
6
 
# Copyright © 2008-2014 Björn Påhlsson
 
5
# Copyright © 2008-2013 Teddy Hogeborn
 
6
# Copyright © 2008-2013 Björn Påhlsson
7
7
8
8
# This program is free software: you can redistribute it and/or modify
9
9
# it under the terms of the GNU General Public License as published by
21
21
# Contact the authors at <mandos@recompile.se>.
22
22
23
23
 
24
 
VERSION="1.6.7"
 
24
VERSION="1.6.4"
25
25
 
26
26
KEYDIR="/etc/keys/mandos"
27
27
KEYTYPE=RSA
33
33
KEYCOMMENT=""
34
34
KEYEXPIRE=0
35
35
FORCE=no
36
 
SSH=yes
37
36
KEYCOMMENT_ORIG="$KEYCOMMENT"
38
37
mode=keygen
39
38
 
42
41
fi
43
42
 
44
43
# Parse options
45
 
TEMP=`getopt --options vhpF:d:t:l:s:L:n:e:c:x:fS \
46
 
    --longoptions version,help,password,passfile:,dir:,type:,length:,subtype:,sublength:,name:,email:,comment:,expire:,force,no-ssh \
 
44
TEMP=`getopt --options vhpF:d:t:l:s:L:n:e:c:x:f \
 
45
    --longoptions version,help,password,passfile:,dir:,type:,length:,subtype:,sublength:,name:,email:,comment:,expire:,force \
47
46
    --name "$0" -- "$@"`
48
47
 
49
48
help(){
86
85
                        Encrypt a password from FILE using the key in
87
86
                        the key directory.  All options other than
88
87
                        --dir and --name are ignored.
89
 
  -S, --no-ssh          Don't get SSH key or set "checker" option.
90
88
EOF
91
89
}
92
90
 
105
103
        -c|--comment) KEYCOMMENT="$2"; shift 2;;
106
104
        -x|--expire) KEYEXPIRE="$2"; shift 2;;
107
105
        -f|--force) FORCE=yes; shift;;
108
 
        -S|--no-ssh) SSH=no; shift;;
109
106
        -v|--version) echo "$0 $VERSION"; exit;;
110
107
        -h|--help) help; exit;;
111
108
        --) shift; break;;
191
188
trap "
192
189
set +e; \
193
190
test -n \"$SECFILE\" && shred --remove \"$SECFILE\"; \
194
 
shred --remove \"$RINGDIR\"/sec* 2>/dev/null;
 
191
shred --remove \"$RINGDIR\"/sec*;
195
192
test -n \"$BATCHFILE\" && rm --force \"$BATCHFILE\"; \
196
193
rm --recursive --force \"$RINGDIR\";
197
194
tty --quiet && stty echo; \
277
274
fi
278
275
 
279
276
if [ "$mode" = password ]; then
280
 
    
281
 
    # Make SSH be 0 or 1
282
 
    case "$SSH" in
283
 
        [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]) SSH=1;;
284
 
        [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|*) SSH=0;;
285
 
    esac
286
 
    
287
 
    if [ $SSH -eq 1 ]; then
288
 
        set +e
289
 
        ssh_fingerprint="`ssh-keyscan localhost 2>/dev/null`"
290
 
        if [ $? -ne 0 ]; then
291
 
            ssh_fingerprint=""
292
 
        fi
293
 
        set -e
294
 
        ssh_fingerprint="${ssh_fingerprint#localhost }"
295
 
    fi
296
 
    
297
277
    # Import key into temporary key rings
298
278
    gpg --quiet --batch --no-tty --no-options --enable-dsa2 \
299
279
        --homedir "$RINGDIR" --trust-model always --armor \
362
342
                /^[^-]/s/^/    /p
363
343
            }
364
344
        }' < "$SECFILE"
365
 
    if [ -n "$ssh_fingerprint" ]; then
366
 
        echo 'checker = ssh-keyscan %%(host)s 2>/dev/null | grep --fixed-strings --line-regexp --quiet --regexp="%%(host)s %(ssh_fingerprint)s"'
367
 
        echo "ssh_fingerprint = ${ssh_fingerprint}"
368
 
    fi
369
345
fi
370
346
 
371
347
trap - EXIT
376
352
    shred --remove "$SECFILE"
377
353
fi
378
354
# Remove the key rings
379
 
shred --remove "$RINGDIR"/sec* 2>/dev/null
 
355
shred --remove "$RINGDIR"/sec*
380
356
rm --recursive --force "$RINGDIR"