Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(ARM).Porting TCP-IP programmer's guide.Ver 1.4.pdf
Скачиваний:
31
Добавлен:
23.08.2013
Размер:
2.79 Mб
Скачать

Miscellaneous Library Functions

11.15userpass.c

The userpass.c file contains code to implement a simple user/password database. It implements the following functions:

add_user() on page 11-36

check_permit() on page 11-37.

11.15.1 add_user()

This function is used to add a username and password to the database.

Syntax

int add_user(char *username, char *password, void *permissions)

where:

username is the name of the user to add.

password is the user’s password.

permissions

is unused (see Usage below).

Return value

Returns one of the following:

TRUE if the user/password combination was accepted.

FALSE if the user/password combination was not accepted.

Usage

The username and password combination specified is added to the table of valid users. The permissions parameter is ignored in the example applications and in this library implementation. However, it could be used for checking that the user has the required access permissions for the operation requested.

The number of users is limited by the value NUM_NETUSERS, defined in userpass.h. The maximum user name and password length are limited by the value

MAX_USERLENGTH, defined in userpass.h.

11-36

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B

Miscellaneous Library Functions

11.15.2 check_permit()

This function is used to authenticate users.

Syntax

int check_permit(char *username, char *password, int appcode, void *permissions)

where:

username is the name of the user to check.

password is the password that the user has entered.

appcode is the application asking for authentication (see Usage below).

permissions

is unused (see Usage below).

Return value

Returns one of the following:

TRUE if the user has been successfully authenticated.

FALSE if the user was not authenticated.

Usage

The check_permit() function is called by an application when it wishes to check if a particular user is authorized to use that application. The username and password values are as entered by the end user, and the appcode is selected from the list in userpass.h. Like add_user(), the permissions parameter is unused in the example applications and in this library implementation, but could be used for checking that the user has the required access permissions for a specific operation, such as writing a system file.

The example implementation of check_permit() simply performs a string comparison of the password and username, and if the two match, it is regarded as a positive authentication. Your implementation will need to implement a proper password authenticating mechanism in order to be secure.

ARM DUI 0079B

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

11-37

Miscellaneous Library Functions

11-38

Copyright © 1998 and 1999 ARM Limited. All rights reserved.

ARM DUI 0079B