FOSSology  4.4.0
Open Source License Compliance by Open Source Software
util.c File Reference

local function of delagent More...

#include <crypt.h>
#include "delagent.h"
Include dependency graph for util.c:

Go to the source code of this file.

Functions

int printfInCaseOfVerbosity (const char *format,...)
 If verbose is on, print to stdout. More...
 
PGresult * PQexecCheck (const char *desc, char *SQL, char *file, const int line)
 simple wrapper which includes PQexec and fo_checkPQcommand More...
 
void PQexecCheckClear (const char *desc, char *SQL, char *file, const int line)
 Execute SQL query and create the result. More...
 
int authentication (char *user, char *password, int *userId, int *userPerm)
 if this account is valid More...
 
int check_permission_upload (int wanted_permissions, long uploadId, int userId, int userPerm)
 check if the upload can be deleted, that is the user have the permission to delete this upload More...
 
int check_read_permission_upload (long uploadId, int userId, int userPerm)
 check if the user has read permission on the given upload More...
 
int check_write_permission_upload (long uploadId, int userId, int userPerm)
 check if the user has read permission on the given upload More...
 
int check_write_permission_folder (long folder_id, int userId, int userPerm)
 check if the upload can be deleted, that is the user have the permission to delete this upload More...
 
int check_write_permission_license (long license_id, int userPerm)
 check if the license can be deleted, that is the user have the permission to delete this license More...
 
int deleteUpload (long uploadId, int userId, int userPerm)
 Given an upload ID, delete it. More...
 
int unlinkContent (long child, long parent, int mode, int userId, int userPerm)
 remove link between parent and (child,mode) if there are other parents More...
 
int listFoldersRecurse (long Parent, int Depth, long Row, int DelFlag, int userId, int userPerm)
 Draw folder tree. More...
 
int listFoldersFindDetatchedFolders (PGresult *result, int userId, int userPerm)
 Given a PGresult, find detached folders. More...
 
int listFoldersFindDetatchedUploads (PGresult *result, int userId, int userPerm)
 Given a PGresult, find detached uploads. More...
 
int listFoldersFindDetatched (int userId, int userPerm)
 Given a user id, find detached folders and uploads. More...
 
int listFolders (int userId, int userPerm)
 List every folder. More...
 
int listUploads (int userId, int userPerm)
 List every upload ID. More...
 
int deleteFolder (long cFolder, long pFolder, int userId, int userPerm)
 recursively delete a folder More...
 
int readAndProcessParameter (char *Parm, int userId, int userPerm)
 Parse parameters. More...
 
void doSchedulerTasks ()
 process the jobs from scheduler More...
 
void exitNow (int exitVal)
 Exit function. This does all cleanup and should be used instead of calling exit() or main() return. More...
 

Variables

int Verbose = 0
 Verbose level. More...
 
int Test = 0
 
PGconn * pgConn = NULL
 Database connection. More...
 

Detailed Description

local function of delagent

delagent: Remove an upload from the DB and repository

Definition in file util.c.

Function Documentation

◆ authentication()

int authentication ( char *  user,
char *  password,
int *  userId,
int *  userPerm 
)

if this account is valid

Parameters
[in]useruser name
[in]passwordpassword
[out]userIdwill be set to the id of the user
[out]userPermwill be set to the permission level of the user
Returns
1: invalid; 0: yes, valid; -1: failure

get user_seed, user_pass on one specified user

Definition at line 96 of file util.c.

◆ check_permission_upload()

int check_permission_upload ( int  wanted_permissions,
long  uploadId,
int  userId,
int  userPerm 
)

check if the upload can be deleted, that is the user have the permission to delete this upload

Parameters
uploadIdupload id
user_nameuser name
Returns
0: yes, you have the needed permissions; 1: no; -1: failure; -2: does not exist

Definition at line 165 of file util.c.

◆ check_read_permission_upload()

int check_read_permission_upload ( long  uploadId,
int  userId,
int  userPerm 
)

check if the user has read permission on the given upload

Parameters
uploadId
userId
userPermPermission requested by user
Returns
0: yes, you have the needed permissions; 1: no; -1: failure; -2: does not exist

Definition at line 196 of file util.c.

◆ check_write_permission_folder()

int check_write_permission_folder ( long  folder_id,
int  userId,
int  userPerm 
)

check if the upload can be deleted, that is the user have the permission to delete this upload

Parameters
uploadIdupload id
user_nameuser name
userPermPermission requested by user
Returns
0: yes, can be deleted; 1: can not be deleted; -1: failure;

Definition at line 228 of file util.c.

◆ check_write_permission_license()

int check_write_permission_license ( long  license_id,
int  userPerm 
)

check if the license can be deleted, that is the user have the permission to delete this license

Parameters
license_idlicense id
userPermPermission requested by user
Returns
0: yes, can be deleted; 1: can not be deleted;

Definition at line 263 of file util.c.

◆ check_write_permission_upload()

int check_write_permission_upload ( long  uploadId,
int  userId,
int  userPerm 
)

check if the user has read permission on the given upload

Parameters
uploadId
userId
userPermPermission requested by user
Returns
0: yes, you have the needed permissions; 1: no; -1: failure; -2: does not exist

Definition at line 211 of file util.c.

◆ deleteFolder()

int deleteFolder ( long  cFolder,
long  pFolder,
int  userId,
int  userPerm 
)

recursively delete a folder

Given a folder ID, delete it AND recursively delete everything below it! This includes upload deletion!

Parameters
cFolderthe folder id to delete
pFolderparent of the current folder
userId
userPermpermission level the user has
Returns
0: success; 1: fail -1: failure

Definition at line 972 of file util.c.

◆ deleteUpload()

int deleteUpload ( long  uploadId,
int  userId,
int  userPerm 
)

Given an upload ID, delete it.

Parameters
uploadIdthe upload id
userId
userPermpermission level the user has
Returns
0: yes, can is deleted; 1: can not be deleted; -1: failure; -2: does not exist

Definition at line 285 of file util.c.

◆ doSchedulerTasks()

void doSchedulerTasks ( )

process the jobs from scheduler

  1. Read the jobs from the scheduler using fo_scheduler_next().
  2. Get the permission level of the current user.
  3. Parse the parameters and process
    See also
    fo_scheduler_next()
    readAndProcessParameter()

Definition at line 1092 of file util.c.

◆ exitNow()

void exitNow ( int  exitVal)

Exit function. This does all cleanup and should be used instead of calling exit() or main() return.

Parameters
ExitValExit value
Returns
void Calls exit()

Definition at line 1131 of file util.c.

◆ listFolders()

int listFolders ( int  userId,
int  userPerm 
)

List every folder.

Parameters
userId
userPermpermission level the user has

Definition at line 875 of file util.c.

◆ listFoldersFindDetatched()

int listFoldersFindDetatched ( int  userId,
int  userPerm 
)

Given a user id, find detached folders and uploads.

Parameters
userId
userPermpermission level the user has
Returns
0: success; 1: fail; -1: failure

Definition at line 843 of file util.c.

◆ listFoldersFindDetatchedFolders()

int listFoldersFindDetatchedFolders ( PGresult *  result,
int  userId,
int  userPerm 
)

Given a PGresult, find detached folders.

Parameters
resultPGresult from a query
userId
userPermpermission level the user has
Returns
0: success; 1: fail; -1: failure

Definition at line 740 of file util.c.

◆ listFoldersFindDetatchedUploads()

int listFoldersFindDetatchedUploads ( PGresult *  result,
int  userId,
int  userPerm 
)

Given a PGresult, find detached uploads.

Parameters
resultPGresult from a query
userId
userPermpermission level the user has
Returns
0: success

Definition at line 794 of file util.c.

◆ listFoldersRecurse()

int listFoldersRecurse ( long  Parent,
int  Depth,
long  Row,
int  DelFlag,
int  userId,
int  userPerm 
)

Draw folder tree.

if DelFlag is set, then all child uploads are deleted and the folders are deleted.

Parameters
Parentthe parent folder id
Depth
rowgrandparent (used to unlink if multiple grandparents)
DelFlag0=no del, 1=del if unique parent, 2=del unconditional
userId
userPermpermission level the user has
Returns
0: success; 1: fail; -1: failure

Definition at line 552 of file util.c.

◆ listUploads()

int listUploads ( int  userId,
int  userPerm 
)

List every upload ID.

Parameters
userIduser id
userPermpermission level the user has
Returns
0 on success; -1 on failure

Definition at line 918 of file util.c.

◆ PQexecCheck()

PGresult* PQexecCheck ( const char *  desc,
char *  SQL,
char *  file,
const int  line 
)

simple wrapper which includes PQexec and fo_checkPQcommand

Parameters
descdescription for the SQL command, else NULL
SQLSQL command executed
filesource file name
linesource line number
Returns
PQexec query result
See also
PQexec()

Definition at line 52 of file util.c.

◆ PQexecCheckClear()

void PQexecCheckClear ( const char *  desc,
char *  SQL,
char *  file,
const int  line 
)

Execute SQL query and create the result.

See also
PQexecCheck()

Definition at line 77 of file util.c.

◆ printfInCaseOfVerbosity()

int printfInCaseOfVerbosity ( const char *  format,
  ... 
)

If verbose is on, print to stdout.

Parameters
formatprintf format to use for printing
...Data to be printed
Returns
Number of characters printed

Definition at line 29 of file util.c.

◆ readAndProcessParameter()

int readAndProcessParameter ( char *  Parm,
int  userId,
int  userPerm 
)

Parse parameters.

Read Parameter from scheduler. Process line elements.

Parameters
Parmthe parameter string
userId
userPermpermission level the user has
Returns
0: yes, can is deleted; 1: can not be deleted; -1: failure; -2: does not exist

Get the type of command: delete or list

Get the target

Definition at line 996 of file util.c.

◆ unlinkContent()

int unlinkContent ( long  child,
long  parent,
int  mode,
int  userId,
int  userPerm 
)

remove link between parent and (child,mode) if there are other parents

Parameters
childid of the child to be unlinked
parentid of the parent to unlink from
mode1<<0 child is folder_fk, 1<<1 child is upload_fk, 1<<2 child is an uploadtree_fk
userPermpermission level the user has
Returns
0: successfully deleted link (other link existed); 1: was not able to delete the link (no other link to this upload existed); -1: failure
Todo:
add permission checks

Definition at line 490 of file util.c.

Variable Documentation

◆ pgConn

PGconn* pgConn = NULL

Database connection.

DB connection.

Definition at line 21 of file util.c.

◆ Test

int Test = 0

Set if working in test mode else 0

Definition at line 20 of file util.c.

◆ Verbose

int Verbose = 0

Verbose level.

Global verbose level.

Contains all the functions supported by delagent

Definition at line 19 of file util.c.