source: rtems/cpukit/libcrypt/crypt.c @ bdd4eb87

5
Last change on this file since bdd4eb87 was 4466321, checked in by Sebastian Huber <sebastian.huber@…>, on 11/13/14 at 14:13:24

Add crypt_r(), etc.

Add crypt_add_format(), crypt_r(), crypt_md5_r(), crypt_sha256_r() and
crypt_sha512_r().

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <crypt.h>
33#include <string.h>
34
35static char *
36cf_default_func(const char *pw, const char *salt, struct crypt_data *data)
37{
38        (void)salt;
39
40        strncpy(&data->buffer[0], pw, sizeof(data->buffer) - 1);
41        data->buffer[sizeof(data->buffer) - 1] = '\0';
42
43        return (&data->buffer[0]);
44}
45
46static struct crypt_format cf_default =
47  CRYPT_FORMAT_INITIALIZER(cf_default_func, NULL);
48
49static SLIST_HEAD(, crypt_format) cf_head = {
50        &cf_default
51};
52
53void crypt_add_format(struct crypt_format *cf)
54{
55        if (cf->link.sle_next == NULL)
56                SLIST_INSERT_HEAD(&cf_head, cf, link);
57}
58
59char *
60crypt_r(const char *passwd, const char *salt, struct crypt_data *data)
61{
62        const struct crypt_format *cf;
63
64        SLIST_FOREACH(cf, &cf_head, link)
65                if (cf->magic != NULL && strstr(salt, cf->magic) == salt)
66                        return (cf->func(passwd, salt, data));
67
68        cf = SLIST_FIRST(&cf_head);
69
70        return (cf->func(passwd, salt, data));
71}
Note: See TracBrowser for help on using the repository browser.