netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
afppasswd.c File Reference

AFP user password utility. More...

`#include <arpa/inet.h>`
`#include <ctype.h>`
`#include <errno.h>`
`#include <fcntl.h>`
`#include <pwd.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/param.h>`
`#include <sys/stat.h>`
`#include <sys/types.h>`
`#include <unistd.h>`
`#include <gcrypt.h>`
`#include <atalk/compat.h>`
`#include <crack.h>`

## Macros
#define | DES_KEY_SZ 8
#define | OPT_ISROOT (1 << 0)
#define | OPT_CREATE (1 << 1)
#define | OPT_FORCE (1 << 2)
#define | OPT_ADDUSER (1 << 3)
#define | OPT_NOCRACK (1 << 4)
#define | OPT_RANDNUM (1 << 5)
#define | PASSWD_ILLEGAL '*'
#define | FORMAT ":****************:****************:********\n"
#define | FORMAT_LEN 44
#define | SRP_SALT_LEN 16
#define | SRP_NBYTES 192 /* 1536-bit prime */
#define | SRP_HEX_SALT_LEN (SRP_SALT_LEN * 2)
#define | SRP_HEX_V_LEN (SRP_NBYTES * 2)
#define | SRP_FORMAT_LEN (1 + SRP_HEX_SALT_LEN + 1 + SRP_HEX_V_LEN + 1)
#define | SRP_SHA1_LEN 20
#define | SRP_PASSWDLEN 255
#define | USERNAME_MAX_LEN 255
#define | UID_START 100
#define | HEXPASSWDLEN 16
#define | PASSWDLEN 8

## Functions
static int | unhex (unsigned char x)
static int | randnum_make_keypath (const char *path, char *keypath, size_t keypath_size)
static int | randnum_read_keyfd (int keyfd, uint8_t key[DES_KEY_SZ], const char *keypath)
static int | randnum_open_keyfile (const char *path, int *keyfd_out)
static int | randnum_write_keyfile (const char *keypath)
static int | randnum_ensure_keyfile (const char *path, int flags)
static int | convert_passwd (char *passwd_buf, char *newpwd, const int keyfd)
static int | srp_compute_verifier (const char *username, const char *password, const unsigned char *salt, unsigned char *v_out)
static void | srp_encode_hex (char *out_hex, const unsigned char *salt, const unsigned char *verifier)
static int | update_srp_passwd (const char *path, const char *name, int flags, const char *pass)
static int | create_srp_file (const char *path, uid_t minuid)
static int | update_passwd (const char *path, const char *name, int flags, const char *pass)
static int | create_file (const char *path, uid_t minuid)
static void | print_usage (void)
int | main (int argc, char **argv)

## Variables
static const unsigned char | srp_N_bytes [SRP_NBYTES]
static char | buf [MAXPATHLEN+1]
static const unsigned char | hextable [] = "0123456789ABCDEF"

## Detailed Description

AFP user password utility.

Supports two modes:

SRP mode (default): Manages SRP verifier file for use with the SRP UAM. Format: username:hex_salt(32):hex_verifier(384)

RandNum mode (-r flag): Manages legacy password file for use with the RandNum UAM. Format: username:hex_password(16):last_login(16):fail_count(8)

## Macro Definition Documentation

## ◆ DES_KEY_SZ

#define DES_KEY_SZ 8

## ◆ FORMAT

#define FORMAT ":****************:****************:********\n"

## ◆ FORMAT_LEN

#define FORMAT_LEN 44

## ◆ HEXPASSWDLEN

#define HEXPASSWDLEN 16

## ◆ OPT_ADDUSER

#define OPT_ADDUSER (1 << 3)

## ◆ OPT_CREATE

#define OPT_CREATE (1 << 1)

## ◆ OPT_FORCE

#define OPT_FORCE (1 << 2)

## ◆ OPT_ISROOT

#define OPT_ISROOT (1 << 0)

## ◆ OPT_NOCRACK

#define OPT_NOCRACK (1 << 4)

## ◆ OPT_RANDNUM

#define OPT_RANDNUM (1 << 5)

## ◆ PASSWD_ILLEGAL

#define PASSWD_ILLEGAL '*'

## ◆ PASSWDLEN

#define PASSWDLEN 8

## ◆ SRP_FORMAT_LEN

#define SRP_FORMAT_LEN (1 + SRP_HEX_SALT_LEN + 1 + SRP_HEX_V_LEN + 1)

## ◆ SRP_HEX_SALT_LEN

#define SRP_HEX_SALT_LEN (SRP_SALT_LEN * 2)

## ◆ SRP_HEX_V_LEN

#define SRP_HEX_V_LEN (SRP_NBYTES * 2)

## ◆ SRP_NBYTES

#define SRP_NBYTES 192 /* 1536-bit prime */

## ◆ SRP_PASSWDLEN

#define SRP_PASSWDLEN 255

## ◆ SRP_SALT_LEN

#define SRP_SALT_LEN 16

## ◆ SRP_SHA1_LEN

#define SRP_SHA1_LEN 20

## ◆ UID_START

#define UID_START 100

## ◆ USERNAME_MAX_LEN

#define USERNAME_MAX_LEN 255

## Function Documentation

## ◆ convert_passwd()

int convert_passwd | ( | char * | passwd_buf,
|  | char * | newpwd,
|  | const int | keyfd )
| static

## ◆ create_file()

int create_file | ( | const char * | path,
|  | uid_t | minuid )
| static

## ◆ create_srp_file()

int create_srp_file | ( | const char * | path,
|  | uid_t | minuid )
| static

## ◆ main()

int main | ( | int | argc,
|  | char ** | argv )

## ◆ print_usage()

void print_usage | ( | void |  | ) |
| static

## ◆ randnum_ensure_keyfile()

int randnum_ensure_keyfile | ( | const char * | path,
|  | int | flags )
| static

## ◆ randnum_make_keypath()

int randnum_make_keypath | ( | const char * | path,
|  | char * | keypath,
|  | size_t | keypath_size )
| static

## ◆ randnum_open_keyfile()

int randnum_open_keyfile | ( | const char * | path,
|  | int * | keyfd_out )
| static

## ◆ randnum_read_keyfd()

int randnum_read_keyfd | ( | int | keyfd,
|  | uint8_t | key[DES_KEY_SZ],
|  | const char * | keypath )
| static

## ◆ randnum_write_keyfile()

int randnum_write_keyfile | ( | const char * | keypath | ) |
| static

## ◆ srp_compute_verifier()

int srp_compute_verifier | ( | const char * | username,
|  | const char * | password,
|  | const unsigned char * | salt,
|  | unsigned char * | v_out )
| static

## ◆ srp_encode_hex()

void srp_encode_hex | ( | char * | out_hex,
|  | const unsigned char * | salt,
|  | const unsigned char * | verifier )
| static

## ◆ unhex()

int unhex | ( | unsigned char | x | ) |
| static

## ◆ update_passwd()

int update_passwd | ( | const char * | path,
|  | const char * | name,
|  | int | flags,
|  | const char * | pass )
| static

## ◆ update_srp_passwd()

int update_srp_passwd | ( | const char * | path,
|  | const char * | name,
|  | int | flags,
|  | const char * | pass )
| static

## Variable Documentation

## ◆ buf

char buf[MAXPATHLEN+1]
| static

## ◆ hextable

const unsigned char hextable[] = "0123456789ABCDEF"
| static

## ◆ srp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