xref: /freebsd/contrib/libfido2/examples/retries.c (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1 /*
2  * Copyright (c) 2018 Yubico AB. All rights reserved.
3  * Use of this source code is governed by a BSD-style
4  * license that can be found in the LICENSE file.
5  * SPDX-License-Identifier: BSD-2-Clause
6  */
7 
8 /*
9  * Get an authenticator's number of PIN attempts left.
10  */
11 
12 #include <fido.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 
16 #include "../openbsd-compat/openbsd-compat.h"
17 
18 int
19 main(int argc, char **argv)
20 {
21 	fido_dev_t	*dev;
22 	int		n;
23 	int		r;
24 
25 	if (argc != 2) {
26 		fprintf(stderr, "usage: retries <device>\n");
27 		exit(EXIT_FAILURE);
28 	}
29 
30 	fido_init(0);
31 
32 	if ((dev = fido_dev_new()) == NULL)
33 		errx(1, "fido_dev_new");
34 
35 	if ((r = fido_dev_open(dev, argv[1])) != FIDO_OK)
36 		errx(1, "fido_open: %s (0x%x)", fido_strerr(r), r);
37 
38 	if ((r = fido_dev_get_retry_count(dev, &n)) != FIDO_OK)
39 		errx(1, "fido_dev_get_retry_count: %s (0x%x)", fido_strerr(r), r);
40 
41 	if ((r = fido_dev_close(dev)) != FIDO_OK)
42 		errx(1, "fido_close: %s (0x%x)", fido_strerr(r), r);
43 
44 	fido_dev_free(&dev);
45 
46 	printf("%d\n", n);
47 
48 	exit(0);
49 }
50