Path: blob/main/contrib/libfido2/examples/setpin.c
39536 views
/*1* Copyright (c) 2018 Yubico AB. All rights reserved.2* Use of this source code is governed by a BSD-style3* license that can be found in the LICENSE file.4* SPDX-License-Identifier: BSD-2-Clause5*/67/*8* Configure a PIN on a given authenticator.9*/1011#include <fido.h>12#include <stdio.h>13#include <stdlib.h>1415#include "../openbsd-compat/openbsd-compat.h"1617static void18setpin(const char *path, const char *pin, const char *oldpin)19{20fido_dev_t *dev;21int r;2223fido_init(0);2425if ((dev = fido_dev_new()) == NULL)26errx(1, "fido_dev_new");2728if ((r = fido_dev_open(dev, path)) != FIDO_OK)29errx(1, "fido_dev_open: %s (0x%x)", fido_strerr(r), r);3031if ((r = fido_dev_set_pin(dev, pin, oldpin)) != FIDO_OK)32errx(1, "fido_dev_set_pin: %s (0x%x)", fido_strerr(r), r);3334if ((r = fido_dev_close(dev)) != FIDO_OK)35errx(1, "fido_dev_close: %s (0x%x)", fido_strerr(r), r);3637fido_dev_free(&dev);38}3940int41main(int argc, char **argv)42{43if (argc < 3 || argc > 4) {44fprintf(stderr, "usage: setpin <pin> [oldpin] <device>\n");45exit(EXIT_FAILURE);46}4748if (argc == 3)49setpin(argv[2], argv[1], NULL);50else51setpin(argv[3], argv[1], argv[2]);5253exit(0);54}555657