1 /*
2   Copyright 2021 Northern.tech AS
3 
4   This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5 
6   This program is free software; you can redistribute it and/or modify it
7   under the terms of the GNU General Public License as published by the
8   Free Software Foundation; version 3.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
18 
19   To the extent this program is licensed as part of the Enterprise
20   versions of CFEngine, the applicable Commercial Open Source License
21   (COSL) may apply to this file if you as a licensee so wish it. See
22   included file COSL.txt.
23 */
24 
25 #ifndef CFENGINE_WINDOWS_FUNCTIONS_H
26 #define CFENGINE_WINDOWS_FUNCTIONS_H
27 
28 #include <fncall.h>
29 
30 #ifdef __MINGW32__
31 /* win_api.c */
32 
33 int NovaWin_chmod(const char *path, mode_t mode);
34 
35 /* win_file.c */
36 
37 int NovaWin_rename(const char *oldpath, const char *newpath);
38 bool NovaWin_FileExists(const char *fileName);
39 bool NovaWin_IsDir(char *fileName);
40 int NovaWin_TakeFileOwnership(char *path);
41 int NovaWin_SetFileOwnership(char *path, SID *sid);
42 off_t NovaWin_GetDiskUsage(char *file, CfSize type);
43 
44 /* win_log.c */
45 
46 void OpenLog(int facility);
47 void CloseLog(void);
48 
49 void LogToSystemLog(const char *msg, LogLevel level);
50 
51 /* win_proc.c */
52 
53 int NovaWin_IsProcessRunning(pid_t pid);
54 int NovaWin_GetCurrentProcessOwner(SID *sid, int sidSz);
55 int NovaWin_SetTokenPrivilege(HANDLE token, char *privilegeName, int enablePriv);
56 
57 /* win_ps.c */
58 
59 int NovaWin_GetProcessSnapshot(Item **procdata);
60 int GatherProcessUsers(Item **userList, int *userListSz, int *numRootProcs, int *numOtherProcs);
61 
62 /* win_service_exec.c */
63 
64 void NovaWin_StartExecService(void);
65 
66 /* win_sysinfo.c */
67 
68 int NovaWin_GetWinDir(char *winDir, int winDirSz);
69 int NovaWin_GetSysDir(char *sysDir, int sysDirSz);
70 int NovaWin_GetProgDir(char *progDir, int progDirSz);
71 int NovaWin_GetEnv(char *varName, char *varContents, int varContentsSz);
72 
73 /* win_user.c */
74 
75 int NovaWin_UserNameToSid(char *userName, SID *sid, DWORD sidSz, int shouldExist);
76 int NovaWin_GroupNameToSid(char *groupName, SID *sid, DWORD sidSz, int shouldExist);
77 int NovaWin_NameToSid(char *name, SID *sid, DWORD sidSz);
78 int NovaWin_SidToName(SID *sid, char *name, int nameSz);
79 int NovaWin_StringToSid(char *stringSid, SID *sid, int sidSz);
80 
81 FnCallResult FnCallUserExists(EvalContext *ctx, const Policy *policy, const FnCall *fp, const Rlist *finalargs);
82 FnCallResult FnCallGroupExists(EvalContext *ctx, const Policy *policy, const FnCall *fp, const Rlist *finalargs);
83 
84 /* win_wmi.c */
85 
86 int NovaWin_PackageListInstalledFromAPI(EvalContext *ctx, PackageItem ** pkgList, const Attributes *a, Promise *pp);
87 
88 /* win_execd_pipe.c */
89 
90 bool IsReadReady(int fd, int timeout_sec);
91 
92 /* win_common.c */
93 
94 void InitializeWindows(void);
95 
96 #endif /* __MINGW32__ */
97 
98 #endif // CFENGINE_WINDOWS_FUNCTIONS_H
99