annotate err.c @ 10:8e9dd5328b5a

Print a warning message when using an insecure algorithm
author Guido Berhoerster <guido+sencrypt@berhoerster.name>
date Sat, 03 Sep 2016 14:02:42 +0200
parents 73af139d1a94
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
1 /*
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
2 * Copyright (C) 2011 Guido Berhoerster <guido+sencrypt@berhoerster.name>
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
3 *
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
4 * Permission is hereby granted, free of charge, to any person obtaining
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
5 * a copy of this software and associated documentation files (the
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
6 * "Software"), to deal in the Software without restriction, including
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
7 * without limitation the rights to use, copy, modify, merge, publish,
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
8 * distribute, sublicense, and/or sell copies of the Software, and to
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
9 * permit persons to whom the Software is furnished to do so, subject to
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
10 * the following conditions:
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
11 *
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
12 * The above copyright notice and this permission notice shall be included
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
13 * in all copies or substantial portions of the Software.
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
14 *
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
22 */
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
23
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
24 #include <stdlib.h>
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
25 #include <stdio.h>
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
26 #include <string.h>
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
27 #include <errno.h>
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
28
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
29 #include "err.h"
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
30
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
31 static char __progname[] = "unknown";
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
32
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
33 void
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
34 err(int eval, const char *fmt, ...)
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
35 {
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
36 va_list args;
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
37
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
38 va_start(args, fmt);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
39 vwarn(fmt, args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
40 va_end(args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
41
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
42 exit(eval);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
43 }
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
44
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
45 void
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
46 errx(int eval, const char *fmt, ...)
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
47 {
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
48 va_list args;
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
49
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
50 va_start(args, fmt);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
51 vwarnx(fmt, args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
52 va_end(args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
53
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
54 exit(eval);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
55 }
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
56
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
57 void
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
58 warn(const char *fmt, ...)
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
59 {
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
60 va_list args;
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
61
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
62 va_start(args, fmt);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
63 vwarn(fmt, args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
64 va_end(args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
65 }
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
66
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
67 void
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
68 warnx(const char *fmt, ...)
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
69 {
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
70 va_list args;
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
71
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
72 va_start(args, fmt);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
73 vwarnx(fmt, args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
74 va_end(args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
75 }
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
76
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
77 void
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
78 verr(int eval, const char *fmt, va_list args)
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
79 {
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
80 vwarn(fmt, args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
81
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
82 exit(eval);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
83 }
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
84
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
85 void
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
86 verrx(int eval, const char *fmt, va_list args)
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
87 {
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
88 vwarnx(fmt, args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
89
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
90 exit(eval);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
91 }
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
92
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
93 void
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
94 vwarn(const char *fmt, va_list args)
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
95 {
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
96 int old_errno = errno;
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
97
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
98 fprintf(stderr, "%s: ", __progname);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
99 if (fmt != NULL) {
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
100 vfprintf(stderr, fmt, args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
101 fprintf(stderr, ": ");
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
102 }
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
103 fprintf(stderr, "%s\n", strerror(old_errno));
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
104 errno = old_errno;
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
105 }
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
106
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
107 void
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
108 vwarnx(const char *fmt, va_list args)
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
109 {
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
110 fprintf(stderr, "%s: ", __progname);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
111 if (fmt != NULL) {
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
112 vfprintf(stderr, fmt, args);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
113 }
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
114 fputc('\n', stderr);
73af139d1a94 Initial revision
Guido Berhoerster <guido+sencrypt@berhoerster.name>
parents:
diff changeset
115 }