forked from aznashwan/chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.h
More file actions
27 lines (20 loc) · 890 Bytes
/
auth.h
File metadata and controls
27 lines (20 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef _AUTHLIB_H
#define _AUTHLIB_H
#include <stdlib.h>
// creds_t is the type representing a set user credentials.
struct creds_t {
char* uname;
char* upass;
};
extern const struct creds_t CREDENTIALS[];
// auth_connection is a helper function which, given the file descriptor of
// a freshly-accepted connection, blocks until both a username and a password
// are provided. If all was well, a pointer to the username of the newly
// authenticated user will be returned, and must be properly freed, otherwise
// NULL will be returned. In case of an error, a negative value is returned.
char* auth_connection(int sockfd);
// verify_creds is a helper function which returns 1 if the given username
// and password are found in the given NULL-terminated list of
// creds_t or 0 if no match was found.
int verify_creds(struct creds_t* creds, char* uname, char* upass);
#endif