xref: /freebsd/contrib/libfido2/examples/reset.c (revision 2ccfa855b2fc331819953e3de1b1c15ce5b95a7e)
10afa8e06SEd Maste /*
2f540a430SEd Maste  * Copyright (c) 2018-2021 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  * Perform a factory reset on a given authenticator.
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 #include "extern.h"
180afa8e06SEd Maste 
190afa8e06SEd Maste int
main(int argc,char ** argv)200afa8e06SEd Maste main(int argc, char **argv)
210afa8e06SEd Maste {
220afa8e06SEd Maste 	fido_dev_t	*dev;
230afa8e06SEd Maste 	int		 r;
240afa8e06SEd Maste 
250afa8e06SEd Maste 	if (argc != 2) {
260afa8e06SEd Maste 		fprintf(stderr, "usage: reset <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_dev_open: %s (0x%x)", fido_strerr(r), r);
370afa8e06SEd Maste 
380afa8e06SEd Maste 	if ((r = fido_dev_reset(dev)) != FIDO_OK) {
390afa8e06SEd Maste 		fido_dev_cancel(dev);
40f540a430SEd Maste 		errx(1, "fido_dev_reset: %s (0x%x)", fido_strerr(r), r);
410afa8e06SEd Maste 	}
420afa8e06SEd Maste 
430afa8e06SEd Maste 	if ((r = fido_dev_close(dev)) != FIDO_OK)
440afa8e06SEd Maste 		errx(1, "fido_dev_close: %s (0x%x)", fido_strerr(r), r);
450afa8e06SEd Maste 
460afa8e06SEd Maste 	fido_dev_free(&dev);
470afa8e06SEd Maste 
480afa8e06SEd Maste 	exit(0);
490afa8e06SEd Maste }
50