function_name
stringlengths
1
80
function
stringlengths
14
10.6k
comment
stringlengths
12
8.02k
normalized_comment
stringlengths
6
6.55k
OSAlert
void OSAlert(char *msg, char *caption) { os->Alert(msg, caption); }
/* Show an alert*/
Show an alert
OSRun
bool OSRun(char *filename, char *arg, bool hide, bool wait) { return os->Run(filename, arg, hide, wait); }
/* Run a process*/
Run a process
OSThreadId
UINT OSThreadId() { return os->ThreadId(); }
/* Get the Thread ID*/
Get the Thread ID
OSFileSize
UINT64 OSFileSize(void *pData) { return os->FileSize(pData); }
/* Get the file size*/
Get the file size
OSFileSeek
bool OSFileSeek(void *pData, UINT mode, int offset) { return os->FileSeek(pData, mode, offset); }
/* Seek the file*/
Seek the file
OSFileDeleteW
bool OSFileDeleteW(wchar_t *name) { return os->FileDeleteW(name); }
/* Delete the file*/
Delete the file
OSMakeDirW
bool OSMakeDirW(wchar_t *name) { return os->MakeDirW(name); }
/* Create a directory*/
Create a directory
OSDeleteDirW
bool OSDeleteDirW(wchar_t *name) { return os->DeleteDirW(name); }
/* Delete the directory*/
Delete the directory
OSFileOpenW
void *OSFileOpenW(wchar_t *name, bool write_mode, bool read_lock) { return os->FileOpenW(name, write_mode, read_lock); }
/* Open the file*/
Open the file
OSFileCreateW
void *OSFileCreateW(wchar_t *name) { return os->FileCreateW(name); }
/* Create a file*/
Create a file
OSFileWrite
bool OSFileWrite(void *pData, void *buf, UINT size) { return os->FileWrite(pData, buf, size); }
/* Write to a file*/
Write to a file
OSFileRead
bool OSFileRead(void *pData, void *buf, UINT size) { return os->FileRead(pData, buf, size); }
/* Read from a file*/
Read from a file
OSFileClose
void OSFileClose(void *pData, bool no_flush) { os->FileClose(pData, no_flush); }
/* Close the file*/
Close the file
OSFileFlush
void OSFileFlush(void *pData) { os->FileFlush(pData); }
/* Flush to the file*/
Flush to the file
OSGetCallStack
CALLSTACK_DATA *OSGetCallStack() { return os->GetCallStack(); }
/* Get the call stack*/
Get the call stack
OSGetCallStackSymbolInfo
bool OSGetCallStackSymbolInfo(CALLSTACK_DATA *s) { return os->GetCallStackSymbolInfo(s); }
/* Get the symbol information*/
Get the symbol information
OSWaitThread
bool OSWaitThread(THREAD *t) { return os->WaitThread(t); }
/* Wait for the termination of the thread*/
Wait for the termination of the thread
OSFreeThread
void OSFreeThread(THREAD *t) { os->FreeThread(t); }
/* Release of thread*/
Release of thread
OSGetTick
UINT OSGetTick() { return os->GetTick(); }
/* Get the system timer*/
Get the system timer
OSGetSystemTime
void OSGetSystemTime(SYSTEMTIME *system_time) { os->GetSystemTime(system_time); }
/* Get the System Time*/
Get the System Time
OSSleep
void OSSleep(UINT time) { os->Sleep(time); }
/* Sleep the thread*/
Sleep the thread
OSNewLock
LOCK *OSNewLock() { return os->NewLock(); }
/* Create a Lock*/
Create a Lock
OSDeleteLock
void OSDeleteLock(LOCK *lock) { os->DeleteLock(lock); }
/* Delete the lock*/
Delete the lock
OSWaitEvent
bool OSWaitEvent(EVENT *event, UINT timeout) { return os->WaitEvent(event, timeout); }
/* Wait for event*/
Wait for event
OSFreeEvent
void OSFreeEvent(EVENT *event) { os->FreeEvent(event); }
/* Release of the event*/
Release of the event
UnixGetDispatchTable
OS_DISPATCH_TABLE *UnixGetDispatchTable() { static OS_DISPATCH_TABLE t = { UnixInit, UnixFree, UnixMemoryAlloc, UnixMemoryReAlloc, UnixMemoryFree, UnixGetTick, UnixGetSystemTime, UnixInc32, UnixDec32, UnixSleep, UnixNewLock, UnixLock, UnixUnlock, UnixDeleteLock, UnixInitEvent, UnixSetEvent, UnixResetEvent, UnixWaitEvent, UnixFreeEvent, UnixWaitThread, UnixFreeThread, UnixInitThread, UnixThreadId, UnixFileOpen, UnixFileOpenW, UnixFileCreate, UnixFileCreateW, UnixFileWrite, UnixFileRead, UnixFileClose, UnixFileFlush, UnixFileSize, UnixFileSeek, UnixFileDelete, UnixFileDeleteW, UnixMakeDir, UnixMakeDirW, UnixDeleteDir, UnixDeleteDirW, UnixGetCallStack, UnixGetCallStackSymbolInfo, UnixFileRename, UnixFileRenameW, UnixRun, UnixRunW, UnixIsSupportedOs, UnixGetOsInfo, UnixAlert, UnixAlertW, UnixGetProductId, UnixSetHighPriority, UnixRestorePriority, UnixNewSingleInstance, UnixFreeSingleInstance, UnixGetMemInfo, UnixYield, }; return &t; }
/* Create a dispatch table*/
Create a dispatch table
UnixIgnoreSignalForThread
void UnixIgnoreSignalForThread(int sig) { struct sigaction sa; Zero(&sa, sizeof(sa)); sa.sa_handler = NULL; sa.sa_sigaction = signal_received_for_ignore; sa.sa_flags = SA_SIGINFO; sigemptyset(&sa.sa_mask); sigaction(SIGUSR1, &sa, NULL); }
/* Ignore the signal flew to the thread*/
Ignore the signal flew to the thread
UnixDisableInterfaceOffload
void UnixDisableInterfaceOffload(char *name) { #ifdef UNIX_LINUX char tmp[MAX_SIZE]; TOKEN_LIST *t; char *names = "rx tx sg tso ufo gso gro lro rxvlan txvlan ntuple rxhash"; // Validate arguments if (name == NULL) { return; } t = ParseToken(names, " "); if (t != NULL) { UINT i; for (i = 0;i < t->NumTokens;i++) { char *a = t->Token[i]; Format(tmp, sizeof(tmp), "ethtool -K %s %s off 2>/dev/null", name, a); FreeToken(UnixExec(tmp)); } } FreeToken(t); #endif // UNIX_LINUX }
/* Disable the off-loading function of the specific Ethernet device*/
Disable the off-loading function of the specific Ethernet device
UnixIsInVmMain
bool UnixIsInVmMain() { TOKEN_LIST *t = NULL; bool ret = false; char *vm_str_list = "Hypervisor detected,VMware Virtual Platform,VMware Virtual USB,qemu,xen,paravirtualized,virtual hd,virtualhd,virtual pc,virtualpc,kvm,oracle vm,oraclevm,parallels,xvm,bochs"; #ifdef UNIX_LINUX t = UnixExec("/bin/dmesg"); if (t != NULL) { BUF *b = NewBuf(); UINT i; for (i = 0;i < t->NumTokens;i++) { char *line = t->Token[i]; AddBufStr(b, line); AddBufStr(b, " "); } WriteBufInt(b, 0); // printf("%s\n", b->Buf); ret = InStrList(b->Buf, vm_str_list, ",", false); FreeBuf(b); FreeToken(t); } #endif // UNIX_LINUX return ret; }
/* Validate whether the UNIX is running in a VM*/
Validate whether the UNIX is running in a VM
UnixExecSilent
void UnixExecSilent(char *cmd) { char tmp[MAX_SIZE]; // Validate arguments if (cmd == NULL) { return; } Format(tmp, sizeof(tmp), "%s 2>/dev/null", cmd); FreeToken(UnixExec(tmp)); }
/* Run quietly in the UNIX*/
Run quietly in the UNIX
UnixSetEnableKernelEspProcessing
void UnixSetEnableKernelEspProcessing(bool b) { if (GetOsInfo()->OsType == OSTYPE_MACOS_X) { // Mac OS X if (b) { UnixExecSilent("/usr/sbin/sysctl -w net.inet.ipsec.esp_port=4500"); } else { UnixExecSilent("/usr/sbin/sysctl -w net.inet.ipsec.esp_port=4501"); } } }
/* Enable / disable the ESP processing in the kernel*/
Enable / disable the ESP processing in the kernel
UnixInitSolarisSleep
void UnixInitSolarisSleep() { char tmp[MAX_SIZE]; UnixNewPipe(&solaris_sleep_p1, &solaris_sleep_p2); (void)read(solaris_sleep_p1, tmp, sizeof(tmp)); }
/* Initialize the Sleep for Solaris*/
Initialize the Sleep for Solaris
UnixFreeSolarisSleep
void UnixFreeSolarisSleep() { UnixDeletePipe(solaris_sleep_p1, solaris_sleep_p2); solaris_sleep_p1 = -1; solaris_sleep_p2 = -1; }
/* Release the Sleep for Solaris*/
Release the Sleep for Solaris
UnixSolarisSleep
void UnixSolarisSleep(UINT msec) { struct pollfd p; memset(&p, 0, sizeof(p)); p.fd = solaris_sleep_p1; p.events = POLLIN; (void)poll(&p, 1, msec == INFINITE ? -1 : (int)msec); }
/* Sleep for Solaris*/
Sleep for Solaris
UnixGetDiskFree
bool UnixGetDiskFree(char *path, UINT64 *free_size, UINT64 *used_size, UINT64 *total_size) { char tmp[MAX_PATH]; bool ret = false; // Validate arguments if (path == NULL) { return false; } NormalizePath(tmp, sizeof(tmp), path); while ((ret = UnixGetDiskFreeMain(tmp, free_size, used_size, total_size)) == false) { if (StrCmpi(tmp, "/") == 0) { break; } GetDirNameFromFilePath(tmp, sizeof(tmp), tmp); } return ret; }
/* Get the free space of the disk*/
Get the free space of the disk
UnixCheckExecAccess
bool UnixCheckExecAccess(char *name) { // Validate arguments if (name == NULL) { return false; } if (access(name, X_OK) == 0) { return true; } return false; }
/* Check the execute permissions of the specified file*/
Check the execute permissions of the specified file
UnixSetThreadPriorityRealtime
void UnixSetThreadPriorityRealtime() { struct sched_param p; Zero(&p, sizeof(p)); p.sched_priority = 255; pthread_setschedparam(pthread_self(), SCHED_RR, &p); }
/* Raise the priority of the thread to highest*/
Raise the priority of the thread to highest
UnixGetCurrentDir
void UnixGetCurrentDir(char *dir, UINT size) { // Validate arguments if (dir == NULL) { return; } getcwd(dir, size); }
/* Get the current directory*/
Get the current directory
UnixGetMemInfo
void UnixGetMemInfo(MEMINFO *info) { // Validate arguments if (info == NULL) { return; } // I don't know!! Zero(info, sizeof(MEMINFO)); }
/* Get the memory information*/
Get the memory information
UnixFreeSingleInstance
void UnixFreeSingleInstance(void *data) { UNIXLOCKFILE *o; struct flock lock; // Validate arguments if (data == NULL) { return; } o = (UNIXLOCKFILE *)data; Zero(&lock, sizeof(lock)); lock.l_type = F_UNLCK; lock.l_whence = SEEK_SET; (void)fcntl(o->fd, F_SETLK, &lock); close(o->fd); (void)remove(o->FileName); Free(data); }
/* Release of the single instance*/
Release of the single instance
UnixSetHighOomScore
void UnixSetHighOomScore() { IO *o; char tmp[256]; sprintf(tmp, "/proc/%u/oom_score_adj", getpid()); o = UnixFileCreate(tmp); if (o != NULL) { char tmp[128]; sprintf(tmp, "%u\n", 800); UnixFileWrite(o, tmp, strlen(tmp)); UnixFileClose(o, false); } }
/* Set the high oom score*/
Set the high oom score
UnixSetHighPriority
void UnixSetHighPriority() { if (high_process == false) { UINT pid = getpid(); UINT pgid = getpgid(pid); high_process = true; nice(-20); setpriority(PRIO_PROCESS, pid, -20); setpriority(PRIO_PGRP, pgid, -20); } }
/* Raise the priority of the process*/
Raise the priority of the process
UnixRestorePriority
void UnixRestorePriority() { if (high_process != false) { high_process = false; nice(20); } }
/* Restore the priority of the process*/
Restore the priority of the process
UnixGetProductId
char *UnixGetProductId() { return CopyStr("--"); }
/* Get the product ID*/
Get the product ID
UnixAlertW
void UnixAlertW(wchar_t *msg, wchar_t *caption) { char *msg8 = CopyUniToUtf(msg); char *caption8 = CopyUniToUtf(caption); UnixAlert(msg8, caption8); Free(msg8); Free(caption8); }
/* Display an alert*/
Display an alert
UnixIsSupportedOs
bool UnixIsSupportedOs() { // Support all UNIX OS which can run PacketiX VPN return true; }
/* Examine whether the current OS is supported by the PacketiX VPN Kernel*/
Examine whether the current OS is supported by the PacketiX VPN Kernel
UnixRunW
bool UnixRunW(wchar_t *filename, wchar_t *arg, bool hide, bool wait) { char *filename8 = CopyUniToUtf(filename); char *arg8 = CopyUniToUtf(arg); bool ret = UnixRun(filename8, arg8, hide, wait); Free(filename8); Free(arg8); return ret; }
/* Run a specified command*/
Run a specified command
UnixCloseIO
void UnixCloseIO() { static bool close_io_first = false; // Execute only once if (close_io_first) { return; } else { close(0); close(1); close(2); (void)open("/dev/null", O_RDWR); dup2(0, 1); dup2(0, 2); close_io_first = false; } }
/* Close the standard I/O*/
Close the standard I/O
UnixFileRenameW
bool UnixFileRenameW(wchar_t *old_name, wchar_t *new_name) { char *old_name8 = CopyUniToUtf(old_name); char *new_name8 = CopyUniToUtf(new_name); bool ret = UnixFileRename(old_name8, new_name8); Free(old_name8); Free(new_name8); return ret; }
/* Change the file name*/
Change the file name
UnixGetCallStack
CALLSTACK_DATA *UnixGetCallStack() { // This is not supported on non-Win32 return NULL; }
/* Get the call stack*/
Get the call stack
UnixGetCallStackSymbolInfo
bool UnixGetCallStackSymbolInfo(CALLSTACK_DATA *s) { // This is not supported on non-Win32 return false; }
/* Get the symbol information from the call stack*/
Get the symbol information from the call stack
UnixDeleteDirW
bool UnixDeleteDirW(wchar_t *name) { char *name8 = CopyUniToUtf(name); bool ret = UnixDeleteDir(name8); Free(name8); return ret; }
/* Delete the directory*/
Delete the directory
UnixMakeDirW
bool UnixMakeDirW(wchar_t *name) { char *name8 = CopyUniToUtf(name); bool ret = UnixMakeDir(name8); Free(name8); return ret; }
/* Create a directory*/
Create a directory
UnixFileDeleteW
bool UnixFileDeleteW(wchar_t *name) { bool ret; char *name8 = CopyUniToUtf(name); ret = UnixFileDelete(name8); Free(name8); return ret; }
/* Delete the file*/
Delete the file
UnixFileSeek
bool UnixFileSeek(void *pData, UINT mode, int offset) { UNIXIO *p; UINT ret; // Validate arguments if (pData == NULL) { return 0; } if (mode != FILE_BEGIN && mode != FILE_END && mode != FILE_CURRENT) { return false; } p = (UNIXIO *)pData; ret = lseek(p->fd, offset, mode); if (ret == -1) { return false; } return true; }
/* Seek the file*/
Seek the file
UnixFileSize
UINT64 UnixFileSize(void *pData) { struct stat st; UNIXIO *p; int r; // Validate arguments if (pData == NULL) { return 0; } p = (UNIXIO *)pData; Zero(&st, sizeof(st)); r = fstat(p->fd, &st); if (r != 0) { return 0; } return (UINT64)st.st_size; }
/* Get the file size*/
Get the file size
UnixFileWrite
bool UnixFileWrite(void *pData, void *buf, UINT size) { UNIXIO *p; UINT ret; // Validate arguments if (pData == NULL || buf == NULL || size == 0) { return false; } p = (UNIXIO *)pData; ret = write(p->fd, buf, size); if (ret != size) { return false; } return true; }
/* Write to the file*/
Write to the file
UnixFileRead
bool UnixFileRead(void *pData, void *buf, UINT size) { UNIXIO *p; UINT ret; // Validate arguments if (pData == NULL || buf == NULL || size == 0) { return false; } p = (UNIXIO *)pData; ret = read(p->fd, buf, size); if (ret != size) { return false; } return true; }
/* Read from the file*/
Read from the file
UnixFileFlush
void UnixFileFlush(void *pData) { UNIXIO *p; bool write_mode; // Validate arguments if (pData == NULL) { return; } p = (UNIXIO *)pData; write_mode = p->write_mode; if (write_mode) { fsync(p->fd); } }
/* Flush to the file*/
Flush to the file
UnixFileClose
void UnixFileClose(void *pData, bool no_flush) { UNIXIO *p; bool write_mode; // Validate arguments if (pData == NULL) { return; } p = (UNIXIO *)pData; write_mode = p->write_mode; if (write_mode && no_flush == false) { fsync(p->fd); } close(p->fd); UnixMemoryFree(p); if (write_mode) { //sync(); } }
/* Close the file*/
Close the file
UnixFileCreateW
void *UnixFileCreateW(wchar_t *name) { void *ret; char *name8 = CopyUniToUtf(name); ret = UnixFileCreate(name8); Free(name8); return ret; }
/* Create a file*/
Create a file
UnixFileOpenW
void *UnixFileOpenW(wchar_t *name, bool write_mode, bool read_lock) { char *name8 = CopyUniToUtf(name); void *ret; ret = UnixFileOpen(name8, write_mode, read_lock); Free(name8); return ret; }
/* Open the file*/
Open the file
GetUnixio4Stdout
void* GetUnixio4Stdout() { static UNIXIO unixio = { .fd = -1, .write_mode = true }; if (g_foreground) { unixio.fd = STDOUT_FILENO; return &unixio; } return NULL; }
/* Get UNIXIO object for stdout*/
Get UNIXIO object for stdout
UnixThreadId
UINT UnixThreadId() { UINT ret; ret = (UINT)pthread_self(); return ret; }
/* Return the current thread ID*/
Return the current thread ID
UnixFreeThread
void UnixFreeThread(THREAD *t) { // Validate arguments if (t == NULL) { return; } // Free memory UnixMemoryFree(t->pData); }
/* Release of thread*/
Release of thread
UnixWaitThread
bool UnixWaitThread(THREAD *t) { UNIXTHREAD *ut; void *retcode = NULL; // Validate arguments if (t == NULL) { return false; } ut = (UNIXTHREAD *)t->pData; if (ut == NULL) { return false; } pthread_join(ut->thread, &retcode); return true; }
/* Wait for the termination of the thread*/
Wait for the termination of the thread
UnixFreeEvent
void UnixFreeEvent(EVENT *event) { UNIXEVENT *ue = (UNIXEVENT *)event->pData; if (ue == NULL) { return; } pthread_cond_destroy(&ue->cond); pthread_mutex_destroy(&ue->mutex); UnixMemoryFree(ue); }
/* Release the event*/
Release the event
UnixResetEvent
void UnixResetEvent(EVENT *event) { UNIXEVENT *ue = (UNIXEVENT *)event->pData; if (ue == NULL) { return; } pthread_mutex_lock(&ue->mutex); ue->signal = false; pthread_cond_signal(&ue->cond); pthread_mutex_unlock(&ue->mutex); }
/* Reset the event*/
Reset the event
UnixSetEvent
void UnixSetEvent(EVENT *event) { UNIXEVENT *ue = (UNIXEVENT *)event->pData; if (ue == NULL) { return; } pthread_mutex_lock(&ue->mutex); ue->signal = true; pthread_cond_signal(&ue->cond); pthread_mutex_unlock(&ue->mutex); }
/* Set the event*/
Set the event
UnixInitEvent
void UnixInitEvent(EVENT *event) { UNIXEVENT *ue = UnixMemoryAlloc(sizeof(UNIXEVENT)); Zero(ue, sizeof(UNIXEVENT)); pthread_cond_init(&ue->cond, NULL); pthread_mutex_init(&ue->mutex, NULL); ue->signal = false; event->pData = (void *)ue; }
/* Initialize the event*/
Initialize the event
UnixDeleteLock
void UnixDeleteLock(LOCK *lock) { pthread_mutex_t *mutex; // Reset Ready flag safely UnixLock(lock); lock->Ready = false; UnixUnlockEx(lock, true); // Delete the mutex mutex = (pthread_mutex_t *)lock->pData; pthread_mutex_destroy(mutex); // Memory release UnixMemoryFree(mutex); UnixMemoryFree(lock); }
/* Delete the lock*/
Delete the lock
UnixNewLock
LOCK *UnixNewLock() { pthread_mutex_t *mutex; // Memory allocation LOCK *lock = UnixMemoryAlloc(sizeof(LOCK)); // Create a mutex mutex = UnixMemoryAlloc(sizeof(pthread_mutex_t)); // Initialization of the mutex pthread_mutex_init(mutex, NULL); lock->pData = (void *)mutex; lock->Ready = true; lock->thread_id = INFINITE; lock->locked_count = 0; return lock; }
/* Creating a new lock*/
Creating a new lock
UnixGetTick64
UINT64 UnixGetTick64() { #if defined(OS_WIN32) || defined(CLOCK_REALTIME) || defined(CLOCK_MONOTONIC) || defined(CLOCK_HIGHRES) struct timespec t; UINT64 ret; Zero(&t, sizeof(t)); // Function to get the boot time of the system // Be careful. The Implementation is depend on the system. #ifdef CLOCK_HIGHRES clock_gettime(CLOCK_HIGHRES, &t); #elif CLOCK_MONOTONIC clock_gettime(CLOCK_MONOTONIC, &t); #else clock_gettime(CLOCK_REALTIME, &t); #endif ret = ((UINT64)((UINT32)t.tv_sec)) * 1000LL + (UINT64)t.tv_nsec / 1000000LL; if (ret == 0) { ret = TickRealtimeManual(); } return ret; #else return TickRealtimeManual(); #endif }
/* Get the system timer (64bit)*/
Get the system timer (64bit)
UnixGetTick
UINT UnixGetTick() { return (UINT)UnixGetTick64(); }
/* Get the system timer*/
Get the system timer
UnixMemoryReAlloc
void *UnixMemoryReAlloc(void *addr, UINT size) { void *r; pthread_mutex_lock(&malloc_lock); r = realloc(addr, size); pthread_mutex_unlock(&malloc_lock); return r; }
/* Reallocation of the memory*/
Reallocation of the memory
UnixMemoryFree
void UnixMemoryFree(void *addr) { pthread_mutex_lock(&malloc_lock); free(addr); pthread_mutex_unlock(&malloc_lock); }
/* Free the memory*/
Free the memory
UnixDisableCoreDump
void UnixDisableCoreDump() { #ifdef RLIMIT_CORE UnixSetResourceLimit(RLIMIT_CORE, 0); #endif // RLIMIT_CORE }
/* Disable core dump*/
Disable core dump
UnixFree
void UnixFree() { UnixFreeSolarisSleep(); current_process_id = 0; pthread_mutex_destroy(&get_time_lock); }
/* Release the library for UNIX*/
Release the library for UNIX
UnixIs64BitRlimSupported
bool UnixIs64BitRlimSupported() { if (sizeof(rlim_t) >= 8) { return true; } return false; }
/* Is the rlim_t type 64-bit?*/
Is the rlim_t type 64-bit?
UnixGenPidFileName
void UnixGenPidFileName(char *name, UINT size) { char exe_name[MAX_PATH]; UCHAR hash[MD5_SIZE]; char tmp1[64]; char dir[MAX_PATH]; // Validate arguments if (name == NULL) { return; } GetPidDir(dir, sizeof(dir)); GetExeName(exe_name, sizeof(exe_name)); StrCat(exe_name, sizeof(exe_name), ":pid_hash"); StrUpper(exe_name); Md5(hash, exe_name, StrLen(exe_name)); BinToStr(tmp1, sizeof(tmp1), hash, sizeof(hash)); Format(name, size, "%s/.pid_%s", dir, tmp1); }
/* Generate the PID file name*/
Generate the PID file name
UnixDeletePidFile
void UnixDeletePidFile() { char tmp[MAX_PATH]; UnixGenPidFileName(tmp, sizeof(tmp)); UnixFileDelete(tmp); }
/* Delete the PID file*/
Delete the PID file
UnixDeleteCtlFile
void UnixDeleteCtlFile() { char tmp[MAX_PATH]; UnixGenCtlFileName(tmp, sizeof(tmp)); UnixFileDelete(tmp); }
/* Delete the CTL file*/
Delete the CTL file
UnixGenCtlFileName
void UnixGenCtlFileName(char *name, UINT size) { char exe_name[MAX_PATH]; UCHAR hash[MD5_SIZE]; char tmp1[64]; char dir[MAX_PATH]; // Validate arguments if (name == NULL) { return; } GetPidDir(dir, sizeof(dir)); GetExeName(exe_name, sizeof(exe_name)); StrCat(exe_name, sizeof(exe_name), ":pid_hash"); StrUpper(exe_name); Md5(hash, exe_name, StrLen(exe_name)); BinToStr(tmp1, sizeof(tmp1), hash, sizeof(hash)); Format(name, size, "%s/.ctl_%s", dir, tmp1); }
/* Generate the CTL file name*/
Generate the CTL file name
UnixWriteCtlFile
void UnixWriteCtlFile(UINT i) { char tmp[MAX_PATH]; char tmp2[64]; IO *o; UnixGenCtlFileName(tmp, sizeof(tmp)); Format(tmp2, sizeof(tmp2), "%u\n", i); o = FileCreate(tmp); if (o != NULL) { FileWrite(o, tmp2, StrLen(tmp2)); FileClose(o); } }
/* Write the CTL file*/
Write the CTL file
UnixWritePidFile
void UnixWritePidFile(UINT pid) { char tmp[MAX_PATH]; char tmp2[64]; IO *o; UnixGenPidFileName(tmp, sizeof(tmp)); Format(tmp2, sizeof(tmp2), "%u\n", pid); o = FileCreate(tmp); if (o != NULL) { FileWrite(o, tmp2, StrLen(tmp2)); FileClose(o); } }
/* Write to the PID file*/
Write to the PID file
UnixReadPidFile
UINT UnixReadPidFile() { char tmp[MAX_PATH]; BUF *buf; UnixGenPidFileName(tmp, sizeof(tmp)); buf = ReadDump(tmp); if (buf == NULL) { return 0; } Zero(tmp, sizeof(tmp)); Copy(tmp, buf->Buf, MIN(buf->Size, sizeof(tmp))); FreeBuf(buf); return ToInt(tmp); }
/* Read the PID file*/
Read the PID file
UnixReadCtlFile
UINT UnixReadCtlFile() { char tmp[MAX_PATH]; BUF *buf; UnixGenCtlFileName(tmp, sizeof(tmp)); buf = ReadDump(tmp); if (buf == NULL) { return 0; } Zero(tmp, sizeof(tmp)); Copy(tmp, buf->Buf, MIN(buf->Size, sizeof(tmp))); FreeBuf(buf); return ToInt(tmp); }
/* Read the CTL file*/
Read the CTL file
UnixGetUID
UINT UnixGetUID() { return (UINT)getuid(); }
/* Get the UID*/
Get the UID
UnixSigTermHandler
void UnixSigTermHandler(int signum) { if (signum == SIGTERM) { unix_svc_terminate = true; } }
/* Handler of the stop signal to the process*/
Handler of the stop signal to the process
UnixStopThread
void UnixStopThread(THREAD *t, void *param) { SERVICE_FUNCTION *stop = (SERVICE_FUNCTION *)param; // Validate arguments if (t == NULL || param == NULL) { return; } stop(); }
/* The thread for stop service*/
The thread for stop service
UnixIsProcess
bool UnixIsProcess(UINT pid) { if (getsid((pid_t)pid) == -1) { return false; } return true; }
/* Get whether the process with the specified pid exists*/
Get whether the process with the specified pid exists
UnixWaitProcessEx
bool UnixWaitProcessEx(UINT pid, UINT timeout) { UINT64 start_tick = Tick64(); UINT64 end_tick = start_tick + (UINT64)timeout; if (timeout == INFINITE) { end_tick = 0; } while (UnixIsProcess(pid)) { if (end_tick != 0) { if (end_tick < Tick64()) { return false; } } SleepThread(100); } return true; }
/* Wait for the termination of the specified process*/
Wait for the termination of the specified process
UnixUsage
void UnixUsage(char *name) { char *svc_name, *svc_title; char tmp[128]; // Validate arguments if (name == NULL) { return; } Format(tmp, sizeof(tmp), SVC_NAME, name); svc_name = _SS(tmp); Format(tmp, sizeof(tmp), SVC_TITLE, name); svc_title = _SS(tmp); UniPrint(_UU("UNIX_SVC_HELP"), svc_title, svc_name, svc_name, svc_title, svc_name, svc_title); }
/* Description of how to start*/
Description of how to start
HashMd4
void HashMd4(void *dst, void *src, UINT size) { // Validate arguments if (dst == NULL || (src == NULL && size != 0)) { return; } MD4(src, size, dst); }
/* MD4 specific hash function*/
MD4 specific hash function
HMacMd5
UINT HMacMd5(void *dst, void *key, UINT key_size, void *src, UINT src_size) { return Internal_HMac(EVP_md5(), dst, key, key_size, src, src_size); }
/* Calculation of HMAC (MD5)*/
Calculation of HMAC (MD5)
HMacSha1
UINT HMacSha1(void *dst, void *key, UINT key_size, void *src, UINT src_size) { return Internal_HMac(EVP_sha1(), dst, key, key_size, src, src_size); }
/* Calculation of HMAC (SHA-1)*/
Calculation of HMAC (SHA-1)
NewMd
MD *NewMd(char *name) { return NewMdEx(name, true); }
/* Creating a message digest object*/
Creating a message digest object
SetMdKey
bool SetMdKey(MD *md, void *key, UINT key_size) { // Validate arguments if (md == NULL || md->IsHMac == false || key == NULL || key_size == 0) { return false; } if (HMAC_Init_ex(md->Ctx, key, key_size, (const EVP_MD *)md->Md, NULL) == false) { Debug("SetMdKey(): HMAC_Init_ex() failed with error: %s\n", OpenSSL_Error()); return false; } return true; }
/* Set the key to the message digest object*/
Set the key to the message digest object
FreeMd
void FreeMd(MD *md) { // Validate arguments if (md == NULL) { return; } if (md->Ctx != NULL) { if (md->IsHMac) { #if OPENSSL_VERSION_NUMBER >= 0x10100000L HMAC_CTX_free(md->Ctx); #else HMAC_CTX_cleanup(md->Ctx); Free(md->Ctx); #endif } else { #if OPENSSL_VERSION_NUMBER >= 0x10100000L EVP_MD_CTX_free(md->Ctx); #else EVP_MD_CTX_destroy(md->Ctx); #endif } } Free(md); }
/* Release of the message digest object*/
Release of the message digest object
SetCipherKey
void SetCipherKey(CIPHER *c, void *key, bool enc) { // Validate arguments if (c == NULL || key == NULL) { return; } if (c->IsNullCipher == false) { if (c->Ctx != NULL) { EVP_CipherInit(c->Ctx, c->Cipher, key, NULL, enc); } } c->Encrypt = enc; }
/* Set the key to the cipher object*/
Set the key to the cipher object