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 #include <cf3.defs.h>
26 #include <known_dirs.h>
27
28 #include <prototypes3.h>
29 #include <syntax.h>
30 #include <eval_context.h>
31 #include <file_lib.h>
32 #include <string_lib.h> // StringCopy()
33
34 #include <enterprise_extension.h>
35
36 /*
37 * This module contains numeruous functions which don't use all their parameters
38 *
39 * Temporarily, in order to avoid cluttering output with thousands of warnings,
40 * this module is excempted from producing warnings about unused function
41 * parameters.
42 *
43 * Please remove this #pragma ASAP and provide ARG_UNUSED declarations for
44 * unused parameters.
45 */
46 #if defined(__GNUC__)
47 #pragma GCC diagnostic ignored "-Wunused-parameter"
48 #endif
49
50 extern int PR_KEPT;
51 extern int PR_REPAIRED;
52 extern int PR_NOTKEPT;
53
ENTERPRISE_VOID_FUNC_1ARG_DEFINE_STUB(void,Nova_Initialize,EvalContext *,ctx)54 ENTERPRISE_VOID_FUNC_1ARG_DEFINE_STUB(void, Nova_Initialize, EvalContext *, ctx)
55 {
56 }
57
58 /* all agents: generic_agent.c */
59
ENTERPRISE_FUNC_0ARG_DEFINE_STUB(const char *,GetConsolePrefix)60 ENTERPRISE_FUNC_0ARG_DEFINE_STUB(const char *, GetConsolePrefix)
61 {
62 return "cf3";
63 }
64
65
66 /* all agents: sysinfo.c */
67
ENTERPRISE_VOID_FUNC_1ARG_DEFINE_STUB(void,EnterpriseContext,ARG_UNUSED EvalContext *,ctx)68 ENTERPRISE_VOID_FUNC_1ARG_DEFINE_STUB(void, EnterpriseContext, ARG_UNUSED EvalContext *, ctx)
69 {
70 }
71
72
73 /* all agents: logging.c */
74
75
ENTERPRISE_VOID_FUNC_2ARG_DEFINE_STUB(void,LogTotalCompliance,const char *,version,int,background_tasks)76 ENTERPRISE_VOID_FUNC_2ARG_DEFINE_STUB(void, LogTotalCompliance, const char *, version, int, background_tasks)
77 {
78 double total = (double) (PR_KEPT + PR_NOTKEPT + PR_REPAIRED) / 100.0;
79
80 char string[CF_BUFSIZE] = { 0 };
81
82 snprintf(string, CF_BUFSIZE,
83 "Outcome of version %s (" CF_AGENTC "-%d): Promises observed to be kept %.2f%%, Promises repaired %.2f%%, Promises not repaired %.2f%%",
84 version, background_tasks,
85 (double) PR_KEPT / total,
86 (double) PR_REPAIRED / total,
87 (double) PR_NOTKEPT / total);
88
89 Log(LOG_LEVEL_VERBOSE, "Logging total compliance, total '%s'", string);
90
91 char filename[CF_BUFSIZE];
92 snprintf(filename, CF_BUFSIZE, "%s/%s", GetLogDir(), CF_PROMISE_LOG);
93 MapName(filename);
94
95 FILE *fout = safe_fopen(filename, "a");
96 if (fout == NULL)
97 {
98 Log(LOG_LEVEL_ERR, "In total compliance logging, could not open file '%s'. (fopen: %s)", filename, GetErrorStr());
99 }
100 else
101 {
102 fprintf(fout, "%jd,%jd: %s\n", (intmax_t)CFSTARTTIME, (intmax_t)time(NULL), string);
103 fclose(fout);
104 }
105 }
106
107
108 /* network communication: cf-serverd.c, client_protocol.c, client_code.c, crypto.c */
109
110
ENTERPRISE_FUNC_1ARG_DEFINE_STUB(int,CfSessionKeySize,char,type)111 ENTERPRISE_FUNC_1ARG_DEFINE_STUB(int, CfSessionKeySize, char, type)
112 {
113 return CF_BLOWFISHSIZE;
114 }
115
ENTERPRISE_FUNC_0ARG_DEFINE_STUB(char,CfEnterpriseOptions)116 ENTERPRISE_FUNC_0ARG_DEFINE_STUB(char, CfEnterpriseOptions)
117 {
118 return 'c';
119 }
120
ENTERPRISE_FUNC_1ARG_DEFINE_STUB(const EVP_CIPHER *,CfengineCipher,char,type)121 ENTERPRISE_FUNC_1ARG_DEFINE_STUB(const EVP_CIPHER *, CfengineCipher, char, type)
122 {
123 return EVP_bf_cbc();
124 }
125
126 /* cf-agent: evalfunction.c */
127
ENTERPRISE_FUNC_6ARG_DEFINE_STUB(char *,GetRemoteScalar,EvalContext *,ctx,char *,proto,char *,handle,const char *,server,int,encrypted,char *,rcv)128 ENTERPRISE_FUNC_6ARG_DEFINE_STUB(char *, GetRemoteScalar, EvalContext *, ctx, char *, proto, char *, handle,
129 const char *, server, int, encrypted, char *, rcv)
130 {
131 Log(LOG_LEVEL_VERBOSE, "Access to server literals is only available in CFEngine Enterprise");
132 return "";
133 }
134
ENTERPRISE_VOID_FUNC_3ARG_DEFINE_STUB(void,CacheUnreliableValue,char *,caller,char *,handle,char *,buffer)135 ENTERPRISE_VOID_FUNC_3ARG_DEFINE_STUB(void, CacheUnreliableValue, char *, caller, char *, handle, char *, buffer)
136 {
137 Log(LOG_LEVEL_VERBOSE, "Value fault-tolerance only available in CFEngine Enterprise");
138 }
139
ENTERPRISE_FUNC_3ARG_DEFINE_STUB(int,RetrieveUnreliableValue,char *,caller,char *,handle,char *,buffer)140 ENTERPRISE_FUNC_3ARG_DEFINE_STUB(int, RetrieveUnreliableValue, char *, caller, char *, handle, char *, buffer)
141 {
142 Log(LOG_LEVEL_VERBOSE, "Value fault-tolerance only available in CFEngine Enterprise");
143 return 0; // enterprise version returns strlen(buffer) or 0 for error
144 }
145
146 #if defined(__MINGW32__)
ENTERPRISE_FUNC_4ARG_DEFINE_STUB(bool,GetRegistryValue,char *,key,char *,name,char *,buf,int,bufSz)147 ENTERPRISE_FUNC_4ARG_DEFINE_STUB(bool, GetRegistryValue, char *, key, char *, name, char *, buf, int, bufSz)
148 {
149 return 0;
150 }
151 #endif
152
ENTERPRISE_FUNC_6ARG_DEFINE_STUB(void *,CfLDAPValue,char *,uri,char *,dn,char *,filter,char *,name,char *,scope,char *,sec)153 ENTERPRISE_FUNC_6ARG_DEFINE_STUB(void *, CfLDAPValue, char *, uri, char *, dn, char *, filter, char *, name, char *, scope, char *, sec)
154 {
155 Log(LOG_LEVEL_ERR, "LDAP support only available in CFEngine Enterprise");
156 return NULL;
157 }
158
ENTERPRISE_FUNC_6ARG_DEFINE_STUB(void *,CfLDAPList,char *,uri,char *,dn,char *,filter,char *,name,char *,scope,char *,sec)159 ENTERPRISE_FUNC_6ARG_DEFINE_STUB(void *, CfLDAPList, char *, uri, char *, dn, char *, filter, char *, name, char *, scope, char *, sec)
160 {
161 Log(LOG_LEVEL_ERR, "LDAP support only available in CFEngine Enterprise");
162 return NULL;
163 }
164
ENTERPRISE_FUNC_8ARG_DEFINE_STUB(void *,CfLDAPArray,EvalContext *,ctx,const Bundle *,caller,char *,array,char *,uri,char *,dn,char *,filter,char *,scope,char *,sec)165 ENTERPRISE_FUNC_8ARG_DEFINE_STUB(void *, CfLDAPArray, EvalContext *, ctx, const Bundle *, caller, char *, array, char *, uri, char *, dn,
166 char *, filter, char *, scope, char *, sec)
167 {
168 Log(LOG_LEVEL_ERR, "LDAP support only available in CFEngine Enterprise");
169 return NULL;
170 }
171
ENTERPRISE_FUNC_8ARG_DEFINE_STUB(void *,CfRegLDAP,EvalContext *,ctx,char *,uri,char *,dn,char *,filter,char *,name,char *,scope,char *,regex,char *,sec)172 ENTERPRISE_FUNC_8ARG_DEFINE_STUB(void *, CfRegLDAP, EvalContext *, ctx, char *, uri, char *, dn, char *, filter, char *, name, char *, scope, char *, regex, char *, sec)
173 {
174 Log(LOG_LEVEL_ERR, "LDAP support only available in CFEngine Enterprise");
175 return NULL;
176 }
177
ENTERPRISE_FUNC_4ARG_DEFINE_STUB(bool,ListHostsWithClass,EvalContext *,ctx,Rlist **,return_list,char *,class_name,char *,return_format)178 ENTERPRISE_FUNC_4ARG_DEFINE_STUB(bool, ListHostsWithClass, EvalContext *, ctx, Rlist **, return_list, char *, class_name, char *, return_format)
179 {
180 Log(LOG_LEVEL_ERR, "Host class counting is only available in CFEngine Enterprise");
181 return false;
182 }
183
184 /* cf-serverd: server_transform.c, cf-serverd.c */
185
ENTERPRISE_FUNC_3ARG_DEFINE_STUB(bool,TranslatePath,const char *,from,char *,to,size_t,to_size)186 ENTERPRISE_FUNC_3ARG_DEFINE_STUB(bool, TranslatePath, const char *, from, char *, to, size_t, to_size)
187 {
188 const size_t length = StringCopy(from, to, to_size);
189 if (length >= to_size)
190 {
191 Log(LOG_LEVEL_ERR,
192 "File name was too long and got truncated: '%s'",
193 to);
194 return false;
195 }
196 return true;
197 }
198
199
ENTERPRISE_VOID_FUNC_3ARG_DEFINE_STUB(void,EvalContextLogPromiseIterationOutcome,ARG_UNUSED EvalContext *,ctx,ARG_UNUSED const Promise *,pp,ARG_UNUSED PromiseResult,result)200 ENTERPRISE_VOID_FUNC_3ARG_DEFINE_STUB(void, EvalContextLogPromiseIterationOutcome,
201 ARG_UNUSED EvalContext *, ctx,
202 ARG_UNUSED const Promise *, pp,
203 ARG_UNUSED PromiseResult, result)
204 {
205 }
206
ENTERPRISE_VOID_FUNC_2ARG_DEFINE_STUB(void,CheckAndSetHAState,ARG_UNUSED const char *,workdir,ARG_UNUSED EvalContext *,ctx)207 ENTERPRISE_VOID_FUNC_2ARG_DEFINE_STUB(void, CheckAndSetHAState, ARG_UNUSED const char *, workdir, ARG_UNUSED EvalContext *, ctx)
208 {
209 }
210
ENTERPRISE_VOID_FUNC_0ARG_DEFINE_STUB(void,ReloadHAConfig)211 ENTERPRISE_VOID_FUNC_0ARG_DEFINE_STUB(void, ReloadHAConfig)
212 {
213 }
214
ENTERPRISE_FUNC_0ARG_DEFINE_STUB(size_t,EnterpriseGetMaxCfHubProcesses)215 ENTERPRISE_FUNC_0ARG_DEFINE_STUB(size_t, EnterpriseGetMaxCfHubProcesses)
216 {
217 return 0;
218 }
219
ENTERPRISE_VOID_FUNC_2ARG_DEFINE_STUB(void,Nova_ClassHistoryAddContextName,ARG_UNUSED const StringSet *,list,ARG_UNUSED const char *,context_name)220 ENTERPRISE_VOID_FUNC_2ARG_DEFINE_STUB(void, Nova_ClassHistoryAddContextName,
221 ARG_UNUSED const StringSet *, list,
222 ARG_UNUSED const char *, context_name)
223 {
224 }
225
ENTERPRISE_VOID_FUNC_2ARG_DEFINE_STUB(void,Nova_ClassHistoryEnable,ARG_UNUSED StringSet **,list,ARG_UNUSED bool,enable)226 ENTERPRISE_VOID_FUNC_2ARG_DEFINE_STUB(void, Nova_ClassHistoryEnable,
227 ARG_UNUSED StringSet **, list,
228 ARG_UNUSED bool, enable)
229 {
230 }
231