mirror of
https://github.com/kingk85/uFTP.git
synced 2025-06-11 01:48:42 +03:00
User and Group ownership management added
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
dist/Debug/GNU-Linux/uftp
vendored
BIN
dist/Debug/GNU-Linux/uftp
vendored
Binary file not shown.
@ -77,7 +77,7 @@ int parseCommandSite(clientDataType *theClientData)
|
|||||||
|
|
||||||
if(compareStringCaseInsensitive(theCommand, "CHMOD", strlen("CHMOD")) == 1)
|
if(compareStringCaseInsensitive(theCommand, "CHMOD", strlen("CHMOD")) == 1)
|
||||||
{
|
{
|
||||||
setPermissions(theCommand, theClientData->login.absolutePath.text);
|
setPermissions(theCommand, theClientData->login.absolutePath.text, theClientData->login.ownerShip);
|
||||||
char *theResponse = "200 Permissions changed\r\n";
|
char *theResponse = "200 Permissions changed\r\n";
|
||||||
returnCode = write(theClientData->socketDescriptor, theResponse, strlen(theResponse));
|
returnCode = write(theClientData->socketDescriptor, theResponse, strlen(theResponse));
|
||||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||||
@ -113,7 +113,6 @@ int parseCommandPass(ftpDataType * data, int socketId)
|
|||||||
char *theResponse = "430 Invalid username or password\r\n";
|
char *theResponse = "430 Invalid username or password\r\n";
|
||||||
returnCode = write(data->clients[socketId].socketDescriptor, theResponse, strlen(theResponse));
|
returnCode = write(data->clients[socketId].socketDescriptor, theResponse, strlen(theResponse));
|
||||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||||
//printf("\nLogin Error recorded no such username or password");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -122,16 +121,15 @@ int parseCommandPass(ftpDataType * data, int socketId)
|
|||||||
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath, strlen(((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath));
|
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath, strlen(((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath));
|
||||||
setDynamicStringDataType(&data->clients[socketId].login.homePath, ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath, strlen(((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath));
|
setDynamicStringDataType(&data->clients[socketId].login.homePath, ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath, strlen(((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->homePath));
|
||||||
setDynamicStringDataType(&data->clients[socketId].login.ftpPath, "/", strlen("/"));
|
setDynamicStringDataType(&data->clients[socketId].login.ftpPath, "/", strlen("/"));
|
||||||
|
|
||||||
|
data->clients[socketId].login.ownerShip.ownerShipSet = ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->ownerShip.ownerShipSet;
|
||||||
|
data->clients[socketId].login.ownerShip.gid = ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->ownerShip.gid;
|
||||||
|
data->clients[socketId].login.ownerShip.uid = ((usersParameters_DataType *) data->ftpParameters.usersVector.Data[searchUserNameIndex])->ownerShip.uid;
|
||||||
data->clients[socketId].login.userLoggedIn = 1;
|
data->clients[socketId].login.userLoggedIn = 1;
|
||||||
|
|
||||||
returnCode = write(data->clients[socketId].socketDescriptor, theResponse, strlen(theResponse));
|
returnCode = write(data->clients[socketId].socketDescriptor, theResponse, strlen(theResponse));
|
||||||
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
if (returnCode <= 0) return FTP_COMMAND_PROCESSED_WRITE_ERROR;
|
||||||
printTimeStamp();
|
printTimeStamp();
|
||||||
|
|
||||||
//printf("PASS COMMAND OK, PASSWORD IS: %s", data->clients[socketId].login.password.text);
|
|
||||||
//printf("\nheClientData->login.homePath: %s", data->clients[socketId].login.homePath.text);
|
|
||||||
//printf("\nheClientData->login.ftpPath: %s", data->clients[socketId].login.ftpPath.text);
|
|
||||||
//printf("\nheClientData->login.absolutePath: %s", data->clients[socketId].login.absolutePath.text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -295,7 +293,6 @@ int parseCommandPort(ftpDataType * data, int socketId)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int parseCommandAbor(ftpDataType * data, int socketId)
|
int parseCommandAbor(ftpDataType * data, int socketId)
|
||||||
{
|
{
|
||||||
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
|
||||||
@ -657,6 +654,11 @@ int parseCommandMkd(clientDataType *theClientData)
|
|||||||
int returnStatus;
|
int returnStatus;
|
||||||
//printf("\nThe directory to make is: %s", mkdFileName.text);
|
//printf("\nThe directory to make is: %s", mkdFileName.text);
|
||||||
returnStatus = mkdir(mkdFileName.text, S_IRWXU | S_IRWXG | S_IRWXO);
|
returnStatus = mkdir(mkdFileName.text, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
|
if (theClientData->login.ownerShip.ownerShipSet == 1)
|
||||||
|
{
|
||||||
|
FILE_doChownFromUidGid(mkdFileName.text, theClientData->login.ownerShip.uid, theClientData->login.ownerShip.gid);
|
||||||
|
}
|
||||||
|
|
||||||
setDynamicStringDataType(&theResponse, "257 \"", strlen("257 \""));
|
setDynamicStringDataType(&theResponse, "257 \"", strlen("257 \""));
|
||||||
appendToDynamicStringDataType(&theResponse, theDirectoryFilename, strlen(theDirectoryFilename));
|
appendToDynamicStringDataType(&theResponse, theDirectoryFilename, strlen(theDirectoryFilename));
|
||||||
appendToDynamicStringDataType(&theResponse, "\" : The directory was successfully created\r\n", strlen("\" : The directory was successfully created\r\n"));
|
appendToDynamicStringDataType(&theResponse, "\" : The directory was successfully created\r\n", strlen("\" : The directory was successfully created\r\n"));
|
||||||
@ -1122,13 +1124,14 @@ int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCo
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int setPermissions(char * permissionsCommand, char * basePath)
|
int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataType ownerShip)
|
||||||
{
|
{
|
||||||
#define STATUS_INCREASE 0
|
#define STATUS_INCREASE 0
|
||||||
#define STATUS_PERMISSIONS 1
|
#define STATUS_PERMISSIONS 1
|
||||||
#define STATUS_LOCAL_PATH 2
|
#define STATUS_LOCAL_PATH 2
|
||||||
|
|
||||||
int permissionsCommandCursor = 0;
|
int permissionsCommandCursor = 0;
|
||||||
|
int returnCode = 0;
|
||||||
|
|
||||||
int status = STATUS_INCREASE;
|
int status = STATUS_INCREASE;
|
||||||
char thePermissionString[1024];
|
char thePermissionString[1024];
|
||||||
@ -1174,14 +1177,37 @@ int setPermissions(char * permissionsCommand, char * basePath)
|
|||||||
//printf("\n thePermissionString = %s ", thePermissionString);
|
//printf("\n thePermissionString = %s ", thePermissionString);
|
||||||
//printf("\n theLocalPathCursor = %s ", theLocalPath);
|
//printf("\n theLocalPathCursor = %s ", theLocalPath);
|
||||||
|
|
||||||
|
//if (basePath[strlen(basePath)-1] != '/')
|
||||||
|
//sprintf(theFinalCommand, "chmod %s %s/%s", thePermissionString, basePath, theLocalPath);
|
||||||
|
//else
|
||||||
|
//sprintf(theFinalCommand, "chmod %s %s%s", thePermissionString, basePath, theLocalPath);
|
||||||
|
|
||||||
|
//printf("\ntheFinalCommand = %s ", theFinalCommand);
|
||||||
|
|
||||||
|
//system(theFinalCommand);
|
||||||
|
if (ownerShip.ownerShipSet == 1)
|
||||||
|
{
|
||||||
|
memset(theFinalCommand, 0, 2048);
|
||||||
if (basePath[strlen(basePath)-1] != '/')
|
if (basePath[strlen(basePath)-1] != '/')
|
||||||
sprintf(theFinalCommand, "chmod %s %s/%s", thePermissionString, basePath, theLocalPath);
|
sprintf(theFinalCommand, "%s/%s", basePath, theLocalPath);
|
||||||
else
|
else
|
||||||
sprintf(theFinalCommand, "chmod %s %s%s", thePermissionString, basePath, theLocalPath);
|
sprintf(theFinalCommand, "%s%s", basePath, theLocalPath);
|
||||||
|
|
||||||
//printf("\n theFinalCommand = %s ", theFinalCommand);
|
FILE_doChownFromUidGid(theFinalCommand, ownerShip.uid, ownerShip.gid);
|
||||||
|
}
|
||||||
|
|
||||||
system(theFinalCommand);
|
memset(theFinalCommand, 0, 2048);
|
||||||
|
|
||||||
|
if (basePath[strlen(basePath)-1] != '/')
|
||||||
|
sprintf(theFinalCommand, "%s/%s", basePath, theLocalPath);
|
||||||
|
else
|
||||||
|
sprintf(theFinalCommand, "%s%s", basePath, theLocalPath);
|
||||||
|
|
||||||
|
returnCode = strtol(thePermissionString, 0, 8);
|
||||||
|
if (chmod (theFinalCommand, returnCode) < 0)
|
||||||
|
{
|
||||||
|
printf("\n---> ERROR WHILE SETTING FILE PERMISSION");
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
@ -75,7 +75,7 @@ int parseCommandRnto(clientDataType *theClientData);
|
|||||||
int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom, FILE *retrFP);
|
int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom, FILE *retrFP);
|
||||||
char *getFtpCommandArg(char * theCommand, char *theCommandString, int skipArgs);
|
char *getFtpCommandArg(char * theCommand, char *theCommandString, int skipArgs);
|
||||||
int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCommandDataType *ftpCommand);
|
int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCommandDataType *ftpCommand);
|
||||||
int setPermissions(char * permissionsCommand, char * basePath);
|
int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataType ownerShip);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -31,7 +30,6 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
#include "ftpServer.h"
|
#include "ftpServer.h"
|
||||||
#include "ftpCommandsElaborate.h"
|
#include "ftpCommandsElaborate.h"
|
||||||
#include "ftpData.h"
|
#include "ftpData.h"
|
||||||
@ -459,7 +457,6 @@ void resetClientData(clientDataType *clientData, int isInitialization)
|
|||||||
|
|
||||||
memset(&clientData->client_sockaddr_in, 0, clientData->sockaddr_in_size);
|
memset(&clientData->client_sockaddr_in, 0, clientData->sockaddr_in_size);
|
||||||
memset(&clientData->server_sockaddr_in, 0, clientData->sockaddr_in_server_size);
|
memset(&clientData->server_sockaddr_in, 0, clientData->sockaddr_in_server_size);
|
||||||
|
|
||||||
memset(clientData->clientIpAddress, 0, INET_ADDRSTRLEN);
|
memset(clientData->clientIpAddress, 0, INET_ADDRSTRLEN);
|
||||||
memset(clientData->buffer, 0, CLIENT_BUFFER_STRING_SIZE);
|
memset(clientData->buffer, 0, CLIENT_BUFFER_STRING_SIZE);
|
||||||
memset(clientData->theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE);
|
memset(clientData->theCommandReceived, 0, CLIENT_COMMAND_STRING_SIZE);
|
||||||
@ -476,11 +473,8 @@ void resetClientData(clientDataType *clientData, int isInitialization)
|
|||||||
cleanDynamicStringDataType(&clientData->ftpCommand.commandArgs, isInitialization);
|
cleanDynamicStringDataType(&clientData->ftpCommand.commandArgs, isInitialization);
|
||||||
cleanDynamicStringDataType(&clientData->ftpCommand.commandOps, isInitialization);
|
cleanDynamicStringDataType(&clientData->ftpCommand.commandOps, isInitialization);
|
||||||
|
|
||||||
|
|
||||||
clientData->connectionTimeStamp = 0;
|
clientData->connectionTimeStamp = 0;
|
||||||
clientData->lastActivityTimeStamp = 0;
|
clientData->lastActivityTimeStamp = 0;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int compareStringCaseInsensitive(char * stringIn, char * stringRef, int stringLenght)
|
int compareStringCaseInsensitive(char * stringIn, char * stringRef, int stringLenght)
|
||||||
|
16
ftpData.h
16
ftpData.h
@ -47,11 +47,25 @@ struct parameter
|
|||||||
char* value;
|
char* value;
|
||||||
} typedef parameter_DataType;
|
} typedef parameter_DataType;
|
||||||
|
|
||||||
|
|
||||||
|
struct ownerShip
|
||||||
|
{
|
||||||
|
int ownerShipSet;
|
||||||
|
char* userOwnerString;
|
||||||
|
char* groupOwnerString;
|
||||||
|
uid_t uid;
|
||||||
|
gid_t gid;
|
||||||
|
|
||||||
|
} typedef ownerShip_DataType;
|
||||||
|
|
||||||
struct usersParameters
|
struct usersParameters
|
||||||
{
|
{
|
||||||
char* name;
|
char* name;
|
||||||
char* password;
|
char* password;
|
||||||
char* homePath;
|
char* homePath;
|
||||||
|
|
||||||
|
ownerShip_DataType ownerShip;
|
||||||
|
|
||||||
} typedef usersParameters_DataType;
|
} typedef usersParameters_DataType;
|
||||||
|
|
||||||
struct ftpParameters
|
struct ftpParameters
|
||||||
@ -85,7 +99,7 @@ struct loginData
|
|||||||
dynamicStringDataType homePath;
|
dynamicStringDataType homePath;
|
||||||
dynamicStringDataType ftpPath;
|
dynamicStringDataType ftpPath;
|
||||||
dynamicStringDataType absolutePath;
|
dynamicStringDataType absolutePath;
|
||||||
|
ownerShip_DataType ownerShip;
|
||||||
} typedef loginDataType;
|
} typedef loginDataType;
|
||||||
|
|
||||||
struct ipData
|
struct ipData
|
||||||
|
@ -220,6 +220,12 @@ void *connectionWorkerHandle(void * socketId)
|
|||||||
fclose(ftpData.clients[theSocketId].workerData.theStorFile);
|
fclose(ftpData.clients[theSocketId].workerData.theStorFile);
|
||||||
ftpData.clients[theSocketId].workerData.theStorFile = NULL;
|
ftpData.clients[theSocketId].workerData.theStorFile = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
if (ftpData.clients[theSocketId].login.ownerShip.ownerShipSet == 1)
|
||||||
|
{
|
||||||
|
FILE_doChownFromUidGid(ftpData.clients[theSocketId].fileToStor.text, ftpData.clients[theSocketId].login.ownerShip.uid, ftpData.clients[theSocketId].login.ownerShip.gid);
|
||||||
|
}
|
||||||
|
|
||||||
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
|
||||||
sprintf(theResponse, "226 file stor ok\r\n");
|
sprintf(theResponse, "226 file stor ok\r\n");
|
||||||
returnCode = write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
|
returnCode = write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
|
||||||
|
@ -346,7 +346,9 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
|||||||
|
|
||||||
char userX[PARAMETER_SIZE_LIMIT],
|
char userX[PARAMETER_SIZE_LIMIT],
|
||||||
passwordX[PARAMETER_SIZE_LIMIT],
|
passwordX[PARAMETER_SIZE_LIMIT],
|
||||||
homeX[PARAMETER_SIZE_LIMIT];
|
homeX[PARAMETER_SIZE_LIMIT],
|
||||||
|
userOwnerX[PARAMETER_SIZE_LIMIT],
|
||||||
|
groupOwnerX[PARAMETER_SIZE_LIMIT];
|
||||||
|
|
||||||
printf("\nReading configuration settings..");
|
printf("\nReading configuration settings..");
|
||||||
|
|
||||||
@ -441,21 +443,33 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
|||||||
memset(userX, 0, PARAMETER_SIZE_LIMIT);
|
memset(userX, 0, PARAMETER_SIZE_LIMIT);
|
||||||
memset(passwordX, 0, PARAMETER_SIZE_LIMIT);
|
memset(passwordX, 0, PARAMETER_SIZE_LIMIT);
|
||||||
memset(homeX, 0, PARAMETER_SIZE_LIMIT);
|
memset(homeX, 0, PARAMETER_SIZE_LIMIT);
|
||||||
|
memset(userOwnerX, 0, PARAMETER_SIZE_LIMIT);
|
||||||
|
memset(groupOwnerX, 0, PARAMETER_SIZE_LIMIT);
|
||||||
|
|
||||||
DYNV_VectorGeneric_Init(&ftpParameters->usersVector);
|
DYNV_VectorGeneric_Init(&ftpParameters->usersVector);
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
int searchUserIndex, searchPasswordIndex, searchHomeIndex;
|
int searchUserIndex, searchPasswordIndex, searchHomeIndex, searchUserOwnerIndex, searchGroupOwnerIndex;
|
||||||
usersParameters_DataType userData;
|
usersParameters_DataType userData;
|
||||||
|
|
||||||
sprintf(userX, "USER_%d", userIndex);
|
sprintf(userX, "USER_%d", userIndex);
|
||||||
sprintf(passwordX, "PASSWORD_%d", userIndex);
|
sprintf(passwordX, "PASSWORD_%d", userIndex);
|
||||||
sprintf(homeX, "HOME_%d", userIndex);
|
sprintf(homeX, "HOME_%d", userIndex);
|
||||||
|
sprintf(groupOwnerX, "GROUP_NAME_OWNER_%d", userIndex);
|
||||||
|
sprintf(userOwnerX, "USER_NAME_OWNER_%d", userIndex);
|
||||||
userIndex++;
|
userIndex++;
|
||||||
|
|
||||||
searchUserIndex = searchParameter(userX, parametersVector);
|
searchUserIndex = searchParameter(userX, parametersVector);
|
||||||
searchPasswordIndex = searchParameter(passwordX, parametersVector);
|
searchPasswordIndex = searchParameter(passwordX, parametersVector);
|
||||||
searchHomeIndex = searchParameter(homeX, parametersVector);
|
searchHomeIndex = searchParameter(homeX, parametersVector);
|
||||||
|
searchUserOwnerIndex = searchParameter(userOwnerX, parametersVector);
|
||||||
|
searchGroupOwnerIndex = searchParameter(groupOwnerX, parametersVector);
|
||||||
|
|
||||||
|
//printf("\ngroupOwnerX = %s", groupOwnerX);
|
||||||
|
//printf("\nuserOwnerX = %s", userOwnerX);
|
||||||
|
//printf("\nsearchUserOwnerIndex = %d", searchUserOwnerIndex);
|
||||||
|
//printf("\nsearchGroupOwnerIndex = %d", searchGroupOwnerIndex);
|
||||||
|
|
||||||
|
|
||||||
if (searchUserIndex == -1 ||
|
if (searchUserIndex == -1 ||
|
||||||
searchPasswordIndex == -1 ||
|
searchPasswordIndex == -1 ||
|
||||||
@ -465,6 +479,8 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userData.ownerShip.groupOwnerString = NULL;
|
||||||
|
userData.ownerShip.userOwnerString = NULL;
|
||||||
userData.name = malloc(strlen(((parameter_DataType *) parametersVector->Data[searchUserIndex])->value) + 1);
|
userData.name = malloc(strlen(((parameter_DataType *) parametersVector->Data[searchUserIndex])->value) + 1);
|
||||||
userData.password = malloc(strlen(((parameter_DataType *) parametersVector->Data[searchPasswordIndex])->value) + 1);
|
userData.password = malloc(strlen(((parameter_DataType *) parametersVector->Data[searchPasswordIndex])->value) + 1);
|
||||||
userData.homePath = malloc(strlen(((parameter_DataType *) parametersVector->Data[searchHomeIndex])->value) + 1);
|
userData.homePath = malloc(strlen(((parameter_DataType *) parametersVector->Data[searchHomeIndex])->value) + 1);
|
||||||
@ -477,10 +493,39 @@ static int parseConfigurationFile(ftpParameters_DataType *ftpParameters, DYNV_Ve
|
|||||||
userData.password[strlen(((parameter_DataType *) parametersVector->Data[searchPasswordIndex])->value)] = '\0';
|
userData.password[strlen(((parameter_DataType *) parametersVector->Data[searchPasswordIndex])->value)] = '\0';
|
||||||
userData.homePath[strlen(((parameter_DataType *) parametersVector->Data[searchHomeIndex])->value)] = '\0';
|
userData.homePath[strlen(((parameter_DataType *) parametersVector->Data[searchHomeIndex])->value)] = '\0';
|
||||||
|
|
||||||
printf("\nUser parameter found");
|
if (searchUserOwnerIndex != -1 &&
|
||||||
|
searchGroupOwnerIndex != -1)
|
||||||
|
{
|
||||||
|
userData.ownerShip.groupOwnerString = malloc(strlen(((parameter_DataType *) parametersVector->Data[searchGroupOwnerIndex])->value) + 1);
|
||||||
|
userData.ownerShip.userOwnerString = malloc(strlen(((parameter_DataType *) parametersVector->Data[searchUserOwnerIndex])->value) + 1);
|
||||||
|
|
||||||
|
strcpy(userData.ownerShip.groupOwnerString, ((parameter_DataType *) parametersVector->Data[searchGroupOwnerIndex])->value);
|
||||||
|
strcpy(userData.ownerShip.userOwnerString, ((parameter_DataType *) parametersVector->Data[searchUserOwnerIndex])->value);
|
||||||
|
|
||||||
|
userData.ownerShip.groupOwnerString[strlen(((parameter_DataType *) parametersVector->Data[searchGroupOwnerIndex])->value)] = '\0';
|
||||||
|
userData.ownerShip.userOwnerString[strlen(((parameter_DataType *) parametersVector->Data[searchUserOwnerIndex])->value)] = '\0';
|
||||||
|
|
||||||
|
userData.ownerShip.gid = FILE_getGID(userData.ownerShip.groupOwnerString);
|
||||||
|
userData.ownerShip.uid = FILE_getUID(userData.ownerShip.userOwnerString);
|
||||||
|
userData.ownerShip.ownerShipSet = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
userData.ownerShip.ownerShipSet = 0;
|
||||||
|
userData.ownerShip.groupOwnerString = NULL;
|
||||||
|
userData.ownerShip.userOwnerString = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\nUser parameter found");
|
||||||
printf("\nName: %s", userData.name);
|
printf("\nName: %s", userData.name);
|
||||||
printf("\nPassword: %s", userData.password);
|
printf("\nPassword: %s", userData.password);
|
||||||
printf("\nHomePath: %s", userData.homePath);
|
printf("\nHomePath: %s", userData.homePath);
|
||||||
|
printf("\ngroupOwnerStr: %s", userData.ownerShip.groupOwnerString);
|
||||||
|
printf("\nuserOwnerStr: %s", userData.ownerShip.userOwnerString);
|
||||||
|
printf("\nuserData.gid = %d", userData.ownerShip.gid);
|
||||||
|
printf("\nuserData.uid = %d", userData.ownerShip.uid);
|
||||||
|
printf("\nuserData.ownerShipSet = %d", userData.ownerShip.ownerShipSet);
|
||||||
|
|
||||||
|
|
||||||
ftpParameters->usersVector.PushBack(&ftpParameters->usersVector, &userData, sizeof(usersParameters_DataType));
|
ftpParameters->usersVector.PushBack(&ftpParameters->usersVector, &userData, sizeof(usersParameters_DataType));
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,17 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "fileManagement.h"
|
#include "fileManagement.h"
|
||||||
#include "dynamicVectors.h"
|
#include "dynamicVectors.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int FILE_CompareString(const void * a, const void * b);
|
static int FILE_CompareString(const void * a, const void * b);
|
||||||
|
|
||||||
static int FILE_CompareString(const void * a, const void * b)
|
static int FILE_CompareString(const void * a, const void * b)
|
||||||
@ -538,3 +543,71 @@ int FILE_LockFile(int fd)
|
|||||||
fl.l_len = 0;
|
fl.l_len = 0;
|
||||||
return(fcntl(fd, F_SETLK, &fl));
|
return(fcntl(fd, F_SETLK, &fl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int FILE_doChownFromUidGid(const char *file_path, uid_t uid, gid_t gid)
|
||||||
|
{
|
||||||
|
if (chown(file_path, uid, gid) == -1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FILE_doChownFromUidGidString ( const char *file_path,
|
||||||
|
const char *user_name,
|
||||||
|
const char *group_name)
|
||||||
|
{
|
||||||
|
uid_t uid;
|
||||||
|
gid_t gid;
|
||||||
|
struct passwd *pwd;
|
||||||
|
struct group *grp;
|
||||||
|
|
||||||
|
pwd = getpwnam(user_name);
|
||||||
|
if (pwd == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
uid = pwd->pw_uid;
|
||||||
|
|
||||||
|
grp = getgrnam(group_name);
|
||||||
|
if (grp == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
gid = grp->gr_gid;
|
||||||
|
|
||||||
|
if (chown(file_path, uid, gid) == -1)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uid_t FILE_getUID(const char *user_name)
|
||||||
|
{
|
||||||
|
struct passwd *pwd;
|
||||||
|
pwd = getpwnam(user_name);
|
||||||
|
|
||||||
|
if (pwd == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pwd->pw_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
gid_t FILE_getGID(const char *group_name)
|
||||||
|
{
|
||||||
|
struct group *grp;
|
||||||
|
grp = getgrnam(group_name);
|
||||||
|
if (grp == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return grp->gr_gid;
|
||||||
|
}
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include "dynamicVectors.h"
|
#include "dynamicVectors.h"
|
||||||
|
|
||||||
#define FILE_MAX_LINE_LENGHT 512
|
#define FILE_MAX_LINE_LENGHT 512
|
||||||
@ -65,5 +66,9 @@
|
|||||||
void FILE_AppendToString(char ** sourceString, char *theString);
|
void FILE_AppendToString(char ** sourceString, char *theString);
|
||||||
void FILE_DirectoryToParent(char ** sourceString);
|
void FILE_DirectoryToParent(char ** sourceString);
|
||||||
int FILE_LockFile(int fd);
|
int FILE_LockFile(int fd);
|
||||||
|
int FILE_doChownFromUidGidString(const char *file_path, const char *user_name, const char *group_name);
|
||||||
|
int FILE_doChownFromUidGid(const char *file_path, uid_t uid, gid_t gid);
|
||||||
|
uid_t FILE_getUID(const char *user_name);
|
||||||
|
gid_t FILE_getGID(const char *group_name);
|
||||||
#define GEN_FILE_MANAGEMENT_TYPES
|
#define GEN_FILE_MANAGEMENT_TYPES
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,7 +7,11 @@
|
|||||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||||
<group>
|
<group>
|
||||||
|
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpData.c</file>
|
||||||
|
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandElaborate.c</file>
|
||||||
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpServer.c</file>
|
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpServer.c</file>
|
||||||
|
<file>file:/home/ugo/NetBeansProjects/uFTP/uFTP.c</file>
|
||||||
|
<file>file:/home/ugo/NetBeansProjects/uFTP/library/configRead.c</file>
|
||||||
</group>
|
</group>
|
||||||
</open-files>
|
</open-files>
|
||||||
</project-private>
|
</project-private>
|
||||||
|
@ -32,9 +32,11 @@ IDLE_MAX_TIMEOUT = 3600
|
|||||||
USER_0 = ugo
|
USER_0 = ugo
|
||||||
PASSWORD_0 = pass
|
PASSWORD_0 = pass
|
||||||
HOME_0 = /
|
HOME_0 = /
|
||||||
|
GROUP_NAME_OWNER_0 = ugo
|
||||||
|
USER_NAME_OWNER_0 = ugo
|
||||||
|
|
||||||
USER_1 = root
|
USER_1 = root
|
||||||
PASSWORD_1 = pass
|
PASSWORD_1 = pass
|
||||||
HOME_1 = /
|
HOME_1 = /
|
||||||
|
GROUP_NAME_OWNER_1 = root
|
||||||
|
USER_NAME_OWNER_1 = root
|
Reference in New Issue
Block a user