home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 May
/
Pcwk5b98.iso
/
WEBSERVE
/
SAMBAR
/
DATA.1
/
login.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-08-19
|
22KB
|
905 lines
/*
** LOGIN
**
** HTTP Wrapper for the Login/Logout/Profile Management Library
**
** Confidential Property of Tod Sambar
** (c) Copyright Tod Sambar 1996-1997
** All rights reserved.
**
**
** Public Functions:
**
** login_init
** user_login
** user_logout
** user_profile
** user_add
** user_delete
** user_update
** user_list
** user_select
** ftp_connect
**
**
** History:
** Chg# Date Description Resp
** ---- ------- ------------------------------------------------------- ----
** 27JAN96 Created sambar
** 29MAR97 Added user list and update functions sambar
** 30MAR97 Added FTP connection security sambar
*/
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <login.h>
/*
** Login RPC Commands
*/
typedef struct login__rpcs
{
SA_CHAR *name;
SA_INT auth;
SA_VOID *func;
SA_CHAR *descr;
} LOGIN__RPCS;
static LOGIN__RPCS login_rpcs[] =
{
{ "adduser", SA_AUTHORIZATION_ADMIN, (SA_VOID *)user_add,
"Add a user to the system." },
{ "upduser", SA_AUTHORIZATION_ADMIN, (SA_VOID *)user_update,
"Update a user." },
{ "deluser", SA_AUTHORIZATION_ADMIN, (SA_VOID *)user_delete,
"Delete a user from the system." },
{ "userprop", SA_AUTHORIZATION_ADMIN, (SA_VOID *)user_prop,
"Get a single user attribute for display." },
{ "listusers", SA_AUTHORIZATION_ADMIN, (SA_VOID *)user_list,
"List users for update/delete." },
{ "selectuser", SA_AUTHORIZATION_ADMIN, (SA_VOID *)user_select,
"List users for selection in a pick list." }
};
/*
** LOGIN_INIT
**
** Initialize the Login/Logout/Profile Interfaces for use by the
** Sambar Server plugins.
**
**
** Parameters:
** sactx Sambar Server context
**
** Returns:
** SA_SUCCEED | SA_FAIL
*/
SA_RETCODE SA_PUBLIC
login_init(sactx)
SA_CTX *sactx;
{
int i;
/* Register the User RPCs with the server */
for (i = 0; i < sizeof(login_rpcs) / sizeof(LOGIN__RPCS); i++)
{
if (sa_cmd_init(sactx, login_rpcs[i].name, login_rpcs[i].auth,
login_rpcs[i].descr, (SA_RPCFUNC)login_rpcs[i].func)
!= SA_SUCCEED)
{
sa_log(sactx, "Unable to initialize User Management RPCs");
return (SA_FAIL);
}
}
sa_log(sactx, "Login/Logout/Profile Management Initialized");
return (SA_SUCCEED);
}
/*
** USER_LOGIN
**
** Login a user. Verify the username/password against the Sambar Server
** password interfaces. Store some profile information for use.
**
** Parameters:
** sactx Sambar Server Application context to release.
** saconn Sambar Server User Connection handle.
** username Name of the user logging in.
** usernamelen Length of the user name
** password Password of the user logging in.
** passwordlen Length of the password.
** infop Error return code
**
** Return Values:
** SA_SUCCESS | SA_FAIL
*/
SA_RETCODE SA_PUBLIC
user_login(sactx, saconn, username, usernamelen, password, passwordlen, infop)
SA_CTX *sactx;
SA_CONN *saconn;
SA_CHAR *username;
SA_INT usernamelen;
SA_CHAR *password;
SA_INT passwordlen;
SA_INT *infop;
{
SA_PASSWD passwd;
LOGIN_PROFILE *profile;
SA_CHAR buffer[512];
if (sa_passwd_lookup(sactx, username, usernamelen, &passwd) != SA_SUCCEED)
{
sprintf(buffer, "Login for user '%s' failed.", username);
sa_log(sactx, buffer);
*infop = SA_E_INVALIDLOGIN;
return (SA_FAIL);
}
/* Verify the passwords are the same */
if ((passwd.passwordlen != passwordlen) ||
(strncmp(passwd.password, password, passwordlen) != 0))
{
sprintf(buffer, "Login for user '%s' failed - bad password (%s)",
username, password);
sa_log(sactx, buffer);
*infop = SA_E_INVALIDLOGIN;
return (SA_FAIL);
}
/* Allocate and populate a user profile structure */
profile = (LOGIN_PROFILE *)malloc(sizeof(LOGIN_PROFILE));
if (profile == (LOGIN_PROFILE *)NULL)
{
sprintf(buffer, "Login for user '%s' failed - no memory", username);
sa_log(sactx, buffer);
*infop = SA_E_INVALIDLOGIN;
return (SA_FAIL);
}
if (passwd.namelen > 0)
memcpy(profile->name, passwd.name, passwd.namelen);
if (passwd.grouplen > 0)
memcpy(profile->group, passwd.group, passwd.grouplen);
memcpy(profile->username, username, usernamelen);
profile->name[passwd.namelen] = '\0';
profile->group[passwd.grouplen] = '\0';
profile->username[usernamelen] = '\0';
/* Save the user's profile handle with the user connection */
if (sa_conn_key(saconn, SA_SET, LOGIN_PROFILE_KEY, (SA_VOID **)profile)
!= SA_SUCCEED)
{
(SA_VOID)free(profile);
sa_log(sactx, "sa_conn_key(SET, LOGIN_PROFILE_KEY) failed!");
return (SA_FAIL);
}
#ifdef DEBUG
sprintf(buffer, "User '%s' logged in.", username);
sa_log(sactx, buffer);
#endif /* DEBUG */
return (SA_SUCCEED);
}
/*
** USER_LOGOUT
**
** Log out a user. Free profile resources.
**
** Parameters:
** sactx Sambar Server Application context to release.
** saconn Sambar Server User Connection handle.
**
** Return Values:
** SA_SUCCESS | SA_FAIL
*/
SA_RETCODE SA_PUBLIC
user_logout(sactx, saconn)
SA_CTX *sactx;
SA_CONN *saconn;
{
LOGIN_PROFILE *profile;
#ifdef DEBUG
SA_CHAR buffer[512];
#endif /* DEBUG */
/* Get the user's pillar handle from the user context */
if (sa_conn_key(saconn, SA_GET, LOGIN_PROFILE_KEY, (SA_VOID **)&profile)
!= SA_SUCCEED)
{
/* User never completed login */
return (SA_SUCCEED);
}
#ifdef DEBUG
sprintf(buffer, "User '%s' logged out.", profile->username);
sa_log(sactx, buffer);
#endif /* DEBUG */
(void)free(profile);
return (SA_SUCCEED);
}
/*
** USER_PROFILE
**
** Respond to a user profile request.
**
** Parameters:
** sactx Sambar Server Application context to release.
** saconn Sambar Server User Connection handle.
** buffer Profile attribute being queried.
** buflen Length of the profile attribute.
** data Buffer for the profile result
** Note: A maximum of 512 bytes may be written to the data buffer.
**
** Return Values:
** SA_SUCCESS | SA_FAIL
*/
SA_RETCODE SA_PUBLIC
user_profile(sactx, saconn, buffer, buflen, data)
SA_CTX *sactx;
SA_CONN *saconn;
SA_CHAR *buffer;
SA_INT buflen;
SA_CHAR *data;
{
LOGIN_PROFILE *profile;
/* Get the user's profile handle */
if (sa_conn_key(saconn, SA_GET, LOGIN_PROFILE_KEY, (SA_VOID **)&profile)
!= SA_SUCCEED)
{
/* User never completed login */
return (SA_FAIL);
}
if (profile == (LOGIN_PROFILE *)NULL)
{
sa_log(sactx, "user_profile: LOGIN_PROFILE_KEY returned NULL!");
return (SA_FAIL);
}
/*
** Profile lookup
*/
if ((buflen == 5) && (strncmp(buffer, "group", 5) == 0))
{
strcpy(data, profile->group);
}
else if ((buflen == 4) && (strncmp(buffer, "name", 4) == 0))
{
strcpy(data, profile->name);
}
else
{
SA_CHAR tmp[512];
sprintf(tmp, "Profile attribute '%s' not supported!", buffer);
sa_log(sactx, tmp);
return (SA_FAIL);
}
return (SA_SUCCEED);
}
/*
** USER_ADD
**
** Add a new user
**
** Parameters:
** sactx Sambar Server context
** saconn Sambar Server connection
** saparams RPC Parameters
** infop Error parameters
**
** Returns:
** SA_SUCCEED | SA_FAIL
*/
SA_RETCODE SA_PUBLIC
user_add(sactx, saconn, saparams, infop)
SA_CTX *sactx;
SA_CONN *saconn;
SA_PARAMS *saparams;
SA_INT *infop;
{
SA_CHAR *data;
SA_INT datalen;
SA_PASSWD passwd;
memset(&passwd, 0, sizeof(SA_PASSWD));
if (sa_param(sactx, saparams, "password", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_add(): Expected parameter 'password'!");
return (SA_FAIL);
}
passwd.passwordlen = MIN(datalen, SA_MAX_NAME);
memcpy(passwd.password, data, passwd.passwordlen);
if (sa_param(sactx, saparams, "group", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_add(): Expected parameter 'group'!");
return (SA_FAIL);
}
passwd.grouplen = MIN(datalen, SA_MAX_NAME);
memcpy(passwd.group, data, passwd.grouplen);
if (sa_param(sactx, saparams, "name", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_add(): Expected parameter 'name'!");
return (SA_FAIL);
}
passwd.namelen = MIN(datalen, SA_MAX_NAME);
memcpy(passwd.name, data, passwd.namelen);
if (sa_param(sactx, saparams, "dir", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_add(): Expected parameter 'dir'!");
return (SA_FAIL);
}
passwd.dirlen = MIN(datalen, SA_MAX_NAME);
memcpy(passwd.dir, data, passwd.dirlen);
if (sa_param(sactx, saparams, "ftpprivs", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_add(): Expected parameter 'ftpprivs'!");
return (SA_FAIL);
}
passwd.ftpprivs = atol(data);
if (sa_param(sactx, saparams, "nntpprivs", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_add(): Expected parameter 'nttpprivs'!");
return (SA_FAIL);
}
passwd.nntpprivs = atol(data);
if (sa_param(sactx, saparams, "username", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_add(): Expected parameter 'username'!");
return (SA_FAIL);
}
if ((datalen == 0) || (datalen > SA_MAX_NAME))
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_add(): 'username' field left NULL!");
return (SA_FAIL);
}
if (sa_passwd_add(sactx, data, datalen, &passwd) != SA_SUCCEED)
{
*infop = SA_E_ALREADYDEFINED;
sa_log(sactx, "user_add(): sa_passwd_add() failed!");
return (SA_FAIL);
}
return (SA_SUCCEED);
}
/*
** USER_UPDATE
**
** Update an existing user
**
** Parameters:
** sactx Sambar Server context
** saconn Sambar Server connection
** saparams RPC Parameters
** infop Error parameters
**
** Returns:
** SA_SUCCEED | SA_FAIL
*/
SA_RETCODE SA_PUBLIC
user_update(sactx, saconn, saparams, infop)
SA_CTX *sactx;
SA_CONN *saconn;
SA_PARAMS *saparams;
SA_INT *infop;
{
SA_CHAR *data;
SA_INT datalen;
SA_PASSWD passwd;
memset(&passwd, 0, sizeof(SA_PASSWD));
if (sa_param(sactx, saparams, "password", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_update(): Expected parameter 'password'!");
return (SA_FAIL);
}
passwd.passwordlen = MIN(datalen, SA_MAX_NAME);
memcpy(passwd.password, data, passwd.passwordlen);
if (sa_param(sactx, saparams, "group", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_update(): Expected parameter 'group'!");
return (SA_FAIL);
}
passwd.grouplen = MIN(datalen, SA_MAX_NAME);
memcpy(passwd.group, data, passwd.grouplen);
if (sa_param(sactx, saparams, "name", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_update(): Expected parameter 'name'!");
return (SA_FAIL);
}
passwd.namelen = MIN(datalen, SA_MAX_NAME);
memcpy(passwd.name, data, passwd.namelen);
if (sa_param(sactx, saparams, "dir", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_update(): Expected parameter 'dir'!");
return (SA_FAIL);
}
passwd.dirlen = MIN(datalen, SA_MAX_NAME);
memcpy(passwd.dir, data, passwd.dirlen);
if (sa_param(sactx, saparams, "ftpprivs", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_update(): Expected parameter 'ftpprivs'!");
return (SA_FAIL);
}
passwd.ftpprivs = atol(data);
if (sa_param(sactx, saparams, "nntpprivs", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_update(): Expected parameter 'nntpprivs'!");
return (SA_FAIL);
}
passwd.nntpprivs = atol(data);
if (sa_param(sactx, saparams, "username", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_update(): Expected parameter 'username'!");
return (SA_FAIL);
}
if ((datalen == 0) || (datalen > SA_MAX_NAME))
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_update(): 'username' field left NULL!");
return (SA_FAIL);
}
if (sa_passwd_update(sactx, data, datalen, &passwd) != SA_SUCCEED)
{
*infop = SA_E_ALREADYDEFINED;
sa_log(sactx, "user_update(): sa_passwd_update() failed!");
return (SA_FAIL);
}
return (SA_SUCCEED);
}
/*
** USER_DELETE
**
** Delete an existing user
**
** Parameters:
** sactx Sambar Server context
** saconn Sambar Server connection
** saparams RPC Parameters
** infop Error parameters
**
** Returns:
** SA_SUCCEED | SA_FAIL
*/
SA_RETCODE SA_PUBLIC
user_delete(sactx, saconn, saparams, infop)
SA_CTX *sactx;
SA_CONN *saconn;
SA_PARAMS *saparams;
SA_INT *infop;
{
SA_INT datalen;
SA_CHAR *data;
if (sa_param(sactx, saparams, "username", &data, &datalen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_delete(): Expected parameter 'username'!");
return (SA_FAIL);
}
if ((datalen == 0) || (datalen > SA_MAX_NAME))
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_delete(): 'username' field left NULL!");
return (SA_FAIL);
}
(SA_VOID)sa_passwd_delete(sactx, data, datalen);
return (SA_SUCCEED);
}
/*
** USER_SELECT
**
** List all users for selection.
**
** Parameters:
** sactx Sambar Server context
** saconn Sambar Server connection
** saparams RPC Parameters
** infop Error parameters
**
** Returns:
** SA_SUCCEED | SA_FAIL
**
** Notes:
** This list is truncated at 100 names.
*/
SA_RETCODE SA_PUBLIC
user_select(sactx, saconn, saparams, infop)
SA_CTX *sactx;
SA_CONN *saconn;
SA_PARAMS *saparams;
SA_INT *infop;
{
SA_INT i;
SA_BOOL selected;
SA_INT usernamelen;
SA_INT numusers;
SA_CHAR *username;
SA_PASSWDUSER users[100];
SA_CHAR buffer[256];
/* If a username is provided make it SELECTED in the OPTION list */
(SA_VOID)sa_param(sactx, saparams, "username", &username, &usernamelen);
if (sa_passwd_list(sactx, users, 100, &numusers) != SA_SUCCEED)
{
sa_log(sactx, "user_select(): failure retrieving names list!");
return (SA_FAIL);
}
/* We could sort the names alphabetically at this point... */
/* Display the list of users. */
for (i = 0; i < numusers; i++)
{
selected = 0;
if ((users[i].usernamelen == usernamelen) &&
(memcmp(username, users[i].username, usernamelen) == 0))
{
selected = 1;
}
sprintf(buffer, "<OPTION %s>%s\n", (selected ? "SELECTED" : ""),
users[i].username);
if (sa_conn_send(saconn, buffer, SA_NULLTERM) != SA_SUCCEED)
return (SA_FAIL);
}
return (SA_SUCCEED);
}
/*
** USER_LIST
**
** List all users for delete or update.
**
** Parameters:
** sactx Sambar Server context
** saconn Sambar Server connection
** saparams RPC Parameters
** infop Error parameters
**
** Returns:
** SA_SUCCEED | SA_FAIL
**
** Notes:
** This list is truncated at 100 names.
*/
SA_RETCODE SA_PUBLIC
user_list(sactx, saconn, saparams, infop)
SA_CTX *sactx;
SA_CONN *saconn;
SA_PARAMS *saparams;
SA_INT *infop;
{
SA_INT i;
SA_INT sysadminlen;
SA_INT numusers;
SA_PASSWDUSER users[100];
SA_CHAR sysadmin[SA_MAX_NAME + 1];
SA_CHAR buffer[256];
/* Get the sysadmin user (disallow deletes) */
if (sa_ctx_props(sactx, SA_GET, SA_CTXPROP_SYSADMIN, (SA_BYTE *)sysadmin,
SA_MAX_NAME, &sysadminlen) != SA_SUCCEED)
{
sa_log(sactx, "user_list(): failure retrieving system admin user!");
return (SA_FAIL);
}
if (sa_passwd_list(sactx, users, 100, &numusers) != SA_SUCCEED)
{
sa_log(sactx, "user_list(): failure retrieving names list!");
return (SA_FAIL);
}
/* We could sort the list alphabetically at this point. */
/* Display the list of users. */
for (i = 0; i < numusers; i++)
{
if ((users[i].usernamelen != sysadminlen) ||
(strncmp(sysadmin, users[i].username, sysadminlen) != 0))
{
sprintf(buffer,
"<A HREF=\"/session/deluser?username=%s&RCpage=/sysadmin/userlist.stm\" onClick=\"return confirmDelete()\"><IMG border=0 HEIGHT=20 WIDTH=20 SRC=\"/images/system/trash.gif\"></A>\n",
users[i].username);
if (sa_conn_send(saconn, buffer, SA_NULLTERM) != SA_SUCCEED)
return (SA_FAIL);
}
sprintf(buffer,
"<A HREF=\"/sysadmin/upduser.stm?RCSusername=%s\" TARGET=body><IMG border=0 HEIGHT=20 WIDTH=20 SRC=\"/images/system/info.gif\"> %s</A><BR>\n",
users[i].username, users[i].username);
if (sa_conn_send(saconn, buffer, SA_NULLTERM) != SA_SUCCEED)
return (SA_FAIL);
}
return (SA_SUCCEED);
}
/*
** USER_PROP
**
** Lookup and return a single user property.
**
** Parameters:
** sactx Sambar Server context
** saconn Sambar Server connection
** saparams RPC Parameters
** infop Error parameters
**
** Return Values:
** SA_SUCCESS | SA_FAIL
*/
SA_RETCODE SA_PUBLIC
user_prop(sactx, saconn, saparams, infop)
SA_CTX *sactx;
SA_CONN *saconn;
SA_PARAMS *saparams;
SA_INT *infop;
{
SA_PASSWD passwd;
SA_INT userlen;
SA_CHAR *user;
SA_INT proplen;
SA_CHAR *prop;
SA_CHAR buffer[256];
/* Get the page to direct to for user update */
if (sa_param(sactx, saparams, "username", &user, &userlen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_prop(): Expected parameter 'username'!");
return (SA_FAIL);
}
if ((userlen == 0) || (userlen > SA_MAX_NAME))
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_prop(): 'username' field left NULL!");
return (SA_FAIL);
}
/* Get the property being looked up. */
if (sa_param(sactx, saparams, "prop", &prop, &proplen) != SA_SUCCEED)
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_prop(): Expected parameter 'prop'!");
return (SA_FAIL);
}
if ((proplen == 0) || (proplen > SA_MAX_NAME))
{
*infop = SA_E_INVALIDDATA;
sa_log(sactx, "user_prop(): 'prop' field left NULL!");
return (SA_FAIL);
}
if (sa_passwd_lookup(sactx, user, userlen, &passwd) != SA_SUCCEED)
{
sprintf(buffer, "User lookup for '%s' failed.", user);
sa_log(sactx, buffer);
*infop = SA_E_INVALIDDATA;
return (SA_FAIL);
}
/* Lookup and return the appropriate property */
if (strcmp(prop, "group") == 0)
{
if (sa_conn_send(saconn, passwd.group, passwd.grouplen) != SA_SUCCEED)
return (SA_FAIL);
}
else if (strcmp(prop, "password") == 0)
{
if (sa_conn_send(saconn, passwd.password, passwd.passwordlen)
!= SA_SUCCEED)
{
return (SA_FAIL);
}
}
else if (strcmp(prop, "name") == 0)
{
if (sa_conn_send(saconn, passwd.name, passwd.namelen) != SA_SUCCEED)
return (SA_FAIL);
}
else if (strcmp(prop, "dir") == 0)
{
if (sa_conn_send(saconn, passwd.dir, passwd.dirlen) != SA_SUCCEED)
return (SA_FAIL);
}
else if (strcmp(prop, "ftpprivs") == 0)
{
if (sa_param(sactx, saparams, "checked", &prop, &proplen) == SA_SUCCEED)
{
int tmp;
tmp = 0;
if (proplen > 0)
tmp = atoi(prop);
if (tmp == passwd.ftpprivs)
{
if (sa_conn_send(saconn, "CHECKED", SA_NULLTERM) != SA_SUCCEED)
return (SA_FAIL);
}
}
else
{
sprintf(buffer, "%ld", passwd.ftpprivs);
if (sa_conn_send(saconn, buffer, SA_NULLTERM) != SA_SUCCEED)
return (SA_FAIL);
}
}
else if (strcmp(prop, "nntpprivs") == 0)
{
if (sa_param(sactx, saparams, "checked", &prop, &proplen) == SA_SUCCEED)
{
int tmp;
tmp = 0;
if (proplen > 0)
tmp = atoi(prop);
if (tmp == passwd.nntpprivs)
{
if (sa_conn_send(saconn, "CHECKED", SA_NULLTERM) != SA_SUCCEED)
return (SA_FAIL);
}
}
else
{
sprintf(buffer, "%ld", passwd.nntpprivs);
if (sa_conn_send(saconn, buffer, SA_NULLTERM) != SA_SUCCEED)
return (SA_FAIL);
}
}
else
{
sprintf(buffer, "User lookup for property '%s' failed.", prop);
sa_log(sactx, buffer);
*infop = SA_E_INVALIDDATA;
return (SA_FAIL);
}
return (SA_SUCCEED);
}
/*
** FTP_CONNECT
**
** Process an FTP Connect request. Verify the username/password against
** the Sambar Server password interfaces and return the root directory
** and priviledges.
**
** Parameters:
** sactx Sambar Server Application context to release.
** saconn Sambar Server User Connection handle.
** username Name of the user logging in.
** usernamelen Length of the user name
** password Password of the user logging in.
** passwordlen Length of the password.
** infop Error return code
**
** Return Values:
** SA_SUCCESS Login Accepted.
** SA_FAIL Login Denied.
*/
SA_RETCODE SA_PUBLIC
ftp_connect(sactx, name, namelen, password, passwordlen, ftpresp)
SA_CTX *sactx;
SA_CHAR *name;
SA_INT namelen;
SA_CHAR *password;
SA_INT passwordlen;
SA_FTP *ftpresp;
{
SA_PASSWD passwd;
SA_CHAR buffer[512];
if (sa_passwd_lookup(sactx, name, namelen, &passwd) != SA_SUCCEED)
{
sprintf(buffer, "FTP login for user '%s' failed.", name);
sa_log(sactx, buffer);
return (SA_FAIL);
}
/* Verify the passwords are the same */
if ((passwd.passwordlen != passwordlen) ||
(strncmp(passwd.password, password, passwordlen) != 0))
{
/* Special case for anonymous user - NULL password match OK */
if ((namelen != 9) || (strncmp(name, "anonymous", 9) != 0))
{
sprintf(buffer, "FTP login for user '%s' failed - bad password (%s)",
name, password);
sa_log(sactx, buffer);
return (SA_FAIL);
}
}
/* Return the directory and access priviledges */
ftpresp->privs = passwd.ftpprivs;
ftpresp->dirlen = passwd.dirlen;
if (ftpresp->dirlen > 0)
strncpy(ftpresp->dir, passwd.dir, ftpresp->dirlen);
ftpresp->dir[ftpresp->dirlen] = '\0';
#ifdef DEBUG
sprintf(buffer, "FTP User '%s' logged in.", name);
sa_log(sactx, buffer);
#endif /* DEBUG */
return (SA_SUCCEED);
}