2016-01-20 02:19:04 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/fsutils/passwd/passwd.h
|
|
|
|
*
|
2020-03-21 18:25:56 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2016-01-20 02:19:04 +01:00
|
|
|
*
|
2020-03-21 18:25:56 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-01-20 02:19:04 +01:00
|
|
|
*
|
2020-03-21 18:25:56 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-01-20 02:19:04 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __APPS_FSUTILS_PASSWD_PASSWD_H
|
2020-01-31 16:18:05 +01:00
|
|
|
#define __APPS_FSUTILS_PASSWD_PASSWD_H
|
2016-01-20 02:19:04 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define MAX_ENCRYPTED 48 /* Maximum size of a password (encrypted, ASCII) */
|
|
|
|
#define MAX_USERNAME 48 /* Maximum size of a username */
|
|
|
|
#define MAX_RECORD (MAX_USERNAME + MAX_ENCRYPTED + 1)
|
2016-01-21 23:26:44 +01:00
|
|
|
|
|
|
|
/* The TEA incryption algorithm generates 8 bytes of encrypted data per
|
|
|
|
* 8 bytes of unencrypted data. The encrypted presentation is base64 which
|
|
|
|
* is 8-bits of ASCII for each 6 bits of data. That is a 3-to-4 expansion
|
|
|
|
* ratio. MAX_ENCRYPTED must be a multiple of 8 bytes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_PASSWORD (3 * MAX_ENCRYPTED / 4)
|
2016-01-20 02:19:04 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2020-03-21 18:31:48 +01:00
|
|
|
* Public Types
|
2016-01-20 02:19:04 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct passwd_s
|
|
|
|
{
|
|
|
|
off_t offset; /* File offset (start of record) */
|
|
|
|
char encrypted[MAX_ENCRYPTED + 1]; /* Encrtyped password in file */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: passwd_lock and passwd_unlock
|
|
|
|
*
|
2016-01-20 02:22:45 +01:00
|
|
|
* Description:
|
2016-01-20 02:19:04 +01:00
|
|
|
* Lock the /etc/passwd file. This is not a real lock at the level of the
|
|
|
|
* file system. Rather, it only prevents concurrent modification of the
|
|
|
|
* /etc/passwd file by passwd_adduser(), passwd_deluser(), and
|
|
|
|
* passwd_update(). Other accesses to /etc/passwd could still cause
|
|
|
|
* concurrency problem and file corruption.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-21 18:25:56 +01:00
|
|
|
#if !defined(CONFIG_FSUTILS_PASSWD_READONLY)
|
2016-01-20 21:41:27 +01:00
|
|
|
# define PASSWD_SEM_DECL(s) FAR sem_t *s
|
2016-01-20 02:19:04 +01:00
|
|
|
int passwd_lock(FAR sem_t **semp);
|
2020-01-09 03:05:50 +01:00
|
|
|
void passwd_unlock(FAR sem_t *sem);
|
2016-01-20 02:19:04 +01:00
|
|
|
#else
|
2016-01-20 21:41:27 +01:00
|
|
|
# define PASSWD_SEM_DECL(s)
|
|
|
|
# define passwd_lock(semp) (0)
|
2020-01-09 03:05:50 +01:00
|
|
|
# define passwd_unlock(sem)
|
2016-01-20 02:19:04 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: passwd_encrypt
|
|
|
|
*
|
2016-01-20 02:22:45 +01:00
|
|
|
* Description:
|
2016-01-20 02:19:04 +01:00
|
|
|
* Encrypt a password. Currently uses the Tiny Encryption Algorithm.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* password -- The password string to be encrypted
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-21 18:31:48 +01:00
|
|
|
int passwd_encrypt(FAR const char *password,
|
|
|
|
char encrypted[MAX_ENCRYPTED + 1]);
|
2016-01-20 02:19:04 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: passwd_append
|
|
|
|
*
|
2016-01-20 02:22:45 +01:00
|
|
|
* Description:
|
2016-01-20 02:19:04 +01:00
|
|
|
* Append a new record to the end of the /etc/passwd file
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int passwd_append(FAR const char *username, FAR const char *password);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: passwd_delete
|
|
|
|
*
|
2016-01-20 02:22:45 +01:00
|
|
|
* Description:
|
2016-01-20 02:19:04 +01:00
|
|
|
* Delete on record from the password file at offset.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int passwd_delete(off_t offset);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: passwd_find
|
|
|
|
*
|
2016-01-20 02:22:45 +01:00
|
|
|
* Description:
|
|
|
|
* Find a password in the
|
2016-01-20 02:19:04 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int passwd_find(FAR const char *username, FAR struct passwd_s *passwd);
|
|
|
|
|
|
|
|
#endif /* __APPS_FSUTILS_PASSWD_PASSWD_H */
|