10afa8e06SEd Maste /*
20afa8e06SEd Maste * Copyright (c) 2018 Yubico AB. All rights reserved.
30afa8e06SEd Maste * Use of this source code is governed by a BSD-style
40afa8e06SEd Maste * license that can be found in the LICENSE file.
5*2ccfa855SEd Maste * SPDX-License-Identifier: BSD-2-Clause
60afa8e06SEd Maste */
70afa8e06SEd Maste
80afa8e06SEd Maste /*
90afa8e06SEd Maste * Get an authenticator's number of PIN attempts left.
100afa8e06SEd Maste */
110afa8e06SEd Maste
120afa8e06SEd Maste #include <fido.h>
130afa8e06SEd Maste #include <stdio.h>
140afa8e06SEd Maste #include <stdlib.h>
150afa8e06SEd Maste
160afa8e06SEd Maste #include "../openbsd-compat/openbsd-compat.h"
170afa8e06SEd Maste
180afa8e06SEd Maste int
main(int argc,char ** argv)190afa8e06SEd Maste main(int argc, char **argv)
200afa8e06SEd Maste {
210afa8e06SEd Maste fido_dev_t *dev;
220afa8e06SEd Maste int n;
230afa8e06SEd Maste int r;
240afa8e06SEd Maste
250afa8e06SEd Maste if (argc != 2) {
260afa8e06SEd Maste fprintf(stderr, "usage: retries <device>\n");
270afa8e06SEd Maste exit(EXIT_FAILURE);
280afa8e06SEd Maste }
290afa8e06SEd Maste
300afa8e06SEd Maste fido_init(0);
310afa8e06SEd Maste
320afa8e06SEd Maste if ((dev = fido_dev_new()) == NULL)
330afa8e06SEd Maste errx(1, "fido_dev_new");
340afa8e06SEd Maste
350afa8e06SEd Maste if ((r = fido_dev_open(dev, argv[1])) != FIDO_OK)
360afa8e06SEd Maste errx(1, "fido_open: %s (0x%x)", fido_strerr(r), r);
370afa8e06SEd Maste
380afa8e06SEd Maste if ((r = fido_dev_get_retry_count(dev, &n)) != FIDO_OK)
39*2ccfa855SEd Maste errx(1, "fido_dev_get_retry_count: %s (0x%x)", fido_strerr(r), r);
400afa8e06SEd Maste
410afa8e06SEd Maste if ((r = fido_dev_close(dev)) != FIDO_OK)
420afa8e06SEd Maste errx(1, "fido_close: %s (0x%x)", fido_strerr(r), r);
430afa8e06SEd Maste
440afa8e06SEd Maste fido_dev_free(&dev);
450afa8e06SEd Maste
460afa8e06SEd Maste printf("%d\n", n);
470afa8e06SEd Maste
480afa8e06SEd Maste exit(0);
490afa8e06SEd Maste }
50