18 #include <mach-o/dyld.h> 30 LOGGER( slog,
"scarab_version" );
76 combine( a_maj_ver, a_min_ver, a_patch_ver );
146 if( a_ver ==
"unknown" )
155 size_t t_delim_pos_1 = a_ver.find(
s_delimeter, 0 );
156 if( t_delim_pos_1 == std::string::npos )
158 LERROR( slog,
"version string <" << a_ver <<
"> is not in the right format (did not find first delimeter)" );
161 std::stringstream t_maj_ver_str;
162 t_maj_ver_str << a_ver.substr( 0, t_delim_pos_1 );
164 size_t t_delim_pos_2 = a_ver.find(
s_delimeter, t_delim_pos_1 + 1 );
165 if( t_delim_pos_2 == std::string::npos )
167 LERROR( slog,
"version string <" << a_ver <<
"> is not in the right format (did not find second delimeter)" );
170 std::stringstream t_min_ver_str;
171 t_min_ver_str << a_ver.substr(t_delim_pos_1 + 1, t_delim_pos_2 );
173 std::stringstream t_patch_ver;
174 t_patch_ver << a_ver.substr( t_delim_pos_2 + 1 );
186 std::stringstream t_ver_str;
194 const size_t t_bufsize = 1024;
198 char t_username_buf[ t_bufsize ];
199 DWORD t_bufsize_win = t_bufsize;
200 if( GetUserName( t_username_buf, &t_bufsize_win ) )
208 passwd* t_passwd = getpwuid( getuid() );
209 if( t_passwd !=
nullptr )
215 LWARN( slog,
"Error reported while getting passwd info: " << strerror( errno ) );
217 LWARN( slog,
"Unable to get the username" );
221 char t_hostname_buf[ t_bufsize ];
224 WSAStartup( MAKEWORD( 2, 2 ), &wsaData );
227 if( gethostname( t_hostname_buf, t_bufsize ) == 0 )
233 LWARN( slog,
"Unable to get the hostname" );
242 TCHAR t_exe_buf[ MAX_PATH ];
243 if( ! GetModuleFileName( NULL, t_exe_buf, MAX_PATH ) )
245 char t_exe_buf[ 2048 ];
246 uint32_t t_exe_bufsize =
sizeof( t_exe_buf );
247 if( _NSGetExecutablePath( t_exe_buf, &t_exe_bufsize ) != 0 )
249 const size_t t_exe_bufsize = 2048;
250 char t_exe_buf[ t_exe_bufsize ];
251 ssize_t t_exe_name_len = readlink(
"/proc/self/exe", t_exe_buf, t_exe_bufsize );
252 if( t_exe_name_len >= 0 )
254 t_exe_buf[t_exe_name_len] =
'\0';
260 LWARN( slog,
"Could not retrieve executable file name" );
262 LWARN( slog,
"Executable name buffer is too small; needs size %u\n" << t_bufsize );
272 std::stringstream t_info_stream;
274 t_info_stream <<
"Executable: " << t_exe_path.filename() <<
'\n';
275 t_info_stream <<
"Location: " << t_exe_path.parent_path() <<
'\n';
277 t_info_stream <<
"Git commit: " <<
f_commit;
278 std::string t_version_info( t_info_stream.str() );
279 return t_version_info;
version_ifc & operator=(const version_ifc &)
bool update_exe_host_user()
bool combine(unsigned a_maj_ver, unsigned a_min_ver, unsigned a_patch_ver)
bool operator<(const version_semantic &a_other)
Less-than operator to compare version information only.
version_semantic & operator=(const version_semantic &a_orig)
Contains the logger class and macros, based on Kasper's KLogger class.
bool operator==(const version_semantic &a_other)
Equality operator to compare version information only.
bool parse(const std::string &a_ver)
virtual std::string version_info_string() const
LOGGER(mtlog,"authentication")