modified: myjupyterlab.sh
[GalaxyCodeBases.git] / etc / Windows / vlmcsd_old_vancepym / output.c
blob22599ed03594c0886ba9c29bd140406c8e2ff6c2
1 #ifndef _DEFAULT_SOURCE
2 #define _DEFAULT_SOURCE
3 #endif // _DEFAULT_SOURCE
5 #ifndef CONFIG
6 #define CONFIG "config.h"
7 #endif // CONFIG
8 #include CONFIG
10 #include "output.h"
11 #include "shared_globals.h"
12 #include "endian.h"
13 #include "helpers.h"
15 #ifndef NO_LOG
16 static void vlogger(const char *message, va_list args)
18 FILE *log;
20 #ifdef _NTSERVICE
21 if (!IsNTService && logstdout) log = stdout;
22 #else
23 if (logstdout) log = stdout;
24 #endif
25 else
27 if (fn_log == NULL) return;
29 #ifndef _WIN32
30 if (!strcmp(fn_log, "syslog"))
32 openlog("vlmcsd", LOG_CONS | LOG_PID, LOG_USER);
34 ////PORTABILITY: vsyslog is not in Posix but virtually all Unixes have it
35 vsyslog(LOG_INFO, message, args);
37 closelog();
38 return;
40 #endif // _WIN32
42 log = fopen(fn_log, "a");
43 if ( !log ) return;
46 time_t now = time(0);
48 #ifdef USE_THREADS
49 char mbstr[2048];
50 #else
51 char mbstr[24];
52 #endif
54 strftime(mbstr, sizeof(mbstr), "%Y-%m-%d %X", localtime(&now));
56 #ifndef USE_THREADS
58 fprintf(log, "%s: ", mbstr);
59 vfprintf(log, message, args);
60 fflush(log);
62 #else // USE_THREADS
64 // We write everything to a string before we really log inside the critical section
65 // so formatting the output can be concurrent
66 strcat(mbstr, ": ");
67 int len = strlen(mbstr);
68 vsnprintf(mbstr + len, sizeof(mbstr) - len, message, args);
70 lock_mutex(&logmutex);
71 fputs(mbstr, log);
72 fflush(log);
73 unlock_mutex(&logmutex);
75 #endif // USE_THREADS
76 if (log != stdout) fclose(log);
80 // Always sends to log output
81 int logger(const char *const fmt, ...)
83 va_list args;
85 va_start(args, fmt);
86 vlogger(fmt, args);
87 va_end(args);
88 return 0;
91 #endif //NO_LOG
94 // Output to stderr if it is available or to log otherwise (e.g. if running as daemon/service)
95 void printerrorf(const char *const fmt, ...)
97 va_list arglist;
99 va_start(arglist, fmt);
101 #ifndef NO_LOG
102 #ifdef _NTSERVICE
103 if (InetdMode || IsNTService)
104 #else // !_NTSERVICE
105 if (InetdMode)
106 #endif // NTSERVIICE
107 vlogger(fmt, arglist);
108 else
109 #endif //NO_LOG
111 vfprintf(stderr, fmt, arglist);
112 fflush(stderr);
115 va_end(arglist);
119 // Always output to stderr
120 int errorout(const char* fmt, ...)
122 va_list args;
124 va_start(args, fmt);
125 int i = vfprintf(stderr, fmt, args);
126 va_end(args);
127 fflush(stderr);
129 return i;
133 static const char *LicenseStatusText[] =
135 "Unlicensed", "Licensed", "OOB grace", "OOT grace", "Non-Genuine", "Notification", "Extended grace"
139 void uuid2StringLE(const GUID *const guid, char *const string)
141 sprintf(string,
142 #ifdef _WIN32
143 "%08x-%04x-%04x-%04x-%012I64x",
144 #else
145 "%08x-%04x-%04x-%04x-%012llx",
146 #endif
147 (unsigned int)LE32( guid->Data1 ),
148 (unsigned int)LE16( guid->Data2 ),
149 (unsigned int)LE16( guid->Data3 ),
150 (unsigned int)BE16( *(uint16_t*)guid->Data4 ),
151 (unsigned long long)BE64(*(uint64_t*)(guid->Data4)) & 0xffffffffffffLL
156 void logRequestVerbose(const REQUEST *const Request, const PRINTFUNC p)
158 char guidBuffer[GUID_STRING_LENGTH + 1];
159 char WorkstationBuffer[3 * WORKSTATION_NAME_BUFFER];
160 const char *productName;
161 ProdListIndex_t index;
163 p("Protocol version : %u.%u\n", LE16(Request->MajorVer), LE16(Request->MinorVer));
164 p("Client is a virtual machine : %s\n", LE32(Request->VMInfo) ? "Yes" : "No");
165 p("Licensing status : %u (%s)\n", (uint32_t)LE32(Request->LicenseStatus), LE32(Request->LicenseStatus) < _countof(LicenseStatusText) ? LicenseStatusText[LE32(Request->LicenseStatus)] : "Unknown");
166 p("Remaining time (0 = forever) : %i minutes\n", (uint32_t)LE32(Request->BindingExpiration));
168 uuid2StringLE(&Request->AppID, guidBuffer);
169 productName = getProductNameLE(&Request->AppID, AppList, &index);
170 p("Application ID : %s (%s)\n", guidBuffer, productName);
172 uuid2StringLE(&Request->ActID, guidBuffer);
174 #ifndef NO_EXTENDED_PRODUCT_LIST
175 productName = getProductNameLE(&Request->ActID, ExtendedProductList, &index);
176 #else
177 productName = "Unknown";
178 #endif
180 p("Activation ID (Product) : %s (%s)\n", guidBuffer, productName);
182 uuid2StringLE(&Request->KMSID, guidBuffer);
184 #ifndef NO_BASIC_PRODUCT_LIST
185 productName = getProductNameLE(&Request->KMSID, ProductList, &index);
186 #else
187 productName = "Unknown";
188 #endif
190 p("Key Management Service ID : %s (%s)\n", guidBuffer, productName);
192 uuid2StringLE(&Request->CMID, guidBuffer);
193 p("Client machine ID : %s\n", guidBuffer);
195 uuid2StringLE(&Request->CMID_prev, guidBuffer);
196 p("Previous client machine ID : %s\n", guidBuffer);
199 char mbstr[64];
200 time_t st;
201 st = fileTimeToUnixTime(&Request->ClientTime);
202 strftime(mbstr, sizeof(mbstr), "%Y-%m-%d %X", gmtime(&st));
203 p("Client request timestamp (UTC) : %s\n", mbstr);
205 ucs2_to_utf8(Request->WorkstationName, WorkstationBuffer, WORKSTATION_NAME_BUFFER, sizeof(WorkstationBuffer));
207 p("Workstation name : %s\n", WorkstationBuffer);
208 p("N count policy (minimum clients): %u\n", (uint32_t)LE32(Request->N_Policy));
212 void logResponseVerbose(const char *const ePID, const BYTE *const hwid, const RESPONSE *const response, const PRINTFUNC p)
214 char guidBuffer[GUID_STRING_LENGTH + 1];
215 //SYSTEMTIME st;
217 p("Protocol version : %u.%u\n", (uint32_t)LE16(response->MajorVer), (uint32_t)LE16(response->MinorVer));
218 p("KMS host extended PID : %s\n", ePID);
219 if (LE16(response->MajorVer) > 5)
220 # ifndef _WIN32
221 p("KMS host Hardware ID : %016llX\n", (unsigned long long)BE64(*(uint64_t*)hwid));
222 # else // _WIN32
223 p("KMS host Hardware ID : %016I64X\n", (unsigned long long)BE64(*(uint64_t*)hwid));
224 # endif // WIN32
226 uuid2StringLE(&response->CMID, guidBuffer);
227 p("Client machine ID : %s\n", guidBuffer);
229 char mbstr[64];
230 time_t st;
232 st = fileTimeToUnixTime(&response->ClientTime);
233 strftime(mbstr, sizeof(mbstr), "%Y-%m-%d %X", gmtime(&st));
234 p("Client request timestamp (UTC) : %s\n", mbstr);
236 p("KMS host current active clients : %u\n", (uint32_t)LE32(response->Count));
237 p("Renewal interval policy : %u\n", (uint32_t)LE32(response->VLRenewalInterval));
238 p("Activation interval policy : %u\n", (uint32_t)LE32(response->VLActivationInterval));