59 {
60 .libname = "libgnunetutil",
61 .project_dirname = "gnunet",
62 .binary_name = "gnunet-arm",
63 .version = PACKAGE_VERSION,
64 .env_varname = "GNUNET_PREFIX",
65 .base_config_varname = "GNUNET_BASE_CONFIG",
66 .bug_email = "gnunet-developers@gnu.org",
67 .homepage = "http://www.gnu.org/s/gnunet/",
68 .config_file = "gnunet.conf",
69 .user_config_file = "~/.config/gnunet.conf",
70 .is_gnu = 1,
71 .gettext_domain = "gnunet",
72 .gettext_path = NULL,
74};
75
76
82{
84}
85
86
87void
90{
91 char *path;
92
95 if (NULL != path)
97 path);
99}
100
101
102#ifdef __linux__
109static char *
111{
112 char fn[64];
115 FILE *f;
116 char *lgu;
117
119 return NULL;
121 sizeof(fn),
122 "/proc/%u/maps",
123 getpid ());
124 if (NULL == (f = fopen (fn, "r")))
125 return NULL;
126 while (NULL != fgets (
line,
sizeof(
line), f))
127 {
128 if ((1 == sscanf (
line,
129 "%*p-%*p %*c%*c%*c%*c %*x %*x:%*x %*u%*[ ]%1023s",
131 (NULL != (lgu = strstr (
dir,
133 {
134 lgu[0] = '\0';
135 fclose (f);
137 }
138 }
139 fclose (f);
140 return NULL;
141}
142
143
150static char *
152{
153 char fn[64];
154 char lnk[1024];
156 char *lep;
157
159 sizeof(fn),
160 "/proc/%u/exe",
161 getpid ());
163 lnk,
164 sizeof(lnk) - 1);
166 {
168 "readlink",
169 fn);
170 return NULL;
171 }
174 while ((lnk[
size] !=
'/') && (
size > 0))
177 "/%s/libexec/",
179
180 if ((((
size_t)
size) > strlen (lep)) &&
181 (0 == strcmp (lep,
182 &lnk[
size - strlen (lep)])))
183 size -= strlen (lep) - 1;
185 if ((
size < 4) || (lnk[
size - 4] !=
'/'))
186 {
187
188 return NULL;
189 }
192}
193
194
195#endif
196
197
198#if DARWIN
206typedef int (*MyNSGetExecutablePathProto) (char *buf,
207 size_t *bufsize);
208
209
215static char *
216get_path_from_NSGetExecutablePath (void)
217{
218 static char zero =
'\0';
219 char *path;
220 size_t len;
221 MyNSGetExecutablePathProto func;
222
223 path = NULL;
224 if (NULL ==
225 (func = (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT,
226 "_NSGetExecutablePath")))
227 return NULL;
229 len = 0;
230
231 (void) func (path, &len);
232 if (0 == len)
233 return NULL;
235 if (0 != func (path, &len))
236 {
238 return NULL;
239 }
240 len = strlen (path);
241 while ((path[len] != '/') && (len > 0))
242 len--;
243 path[len] = '\0';
244 return path;
245}
246
247
253static char *
254get_path_from_dyld_image (void)
255{
256 const char *path;
258 char *s;
259 unsigned int i;
260 int c;
261
262 c = _dyld_image_count ();
263 for (i = 0; i < c; i++)
264 {
265 if (((const void *) _dyld_get_image_header (i)) !=
266 ((const void *) &_mh_dylib_header))
267 continue;
268 path = _dyld_get_image_name (i);
269 if ((NULL == path) || (0 == strlen (path)))
270 continue;
273 while ((s >
p) && (
'/' != *s))
274 s--;
275 s++;
276 *s = '\0';
278 }
279 return NULL;
280}
281
282
283#endif
284
285
293static char *
295{
296 char *path;
297 char *pos;
299 char *buf;
301
302 if (NULL == (
p =
getenv (
"PATH")))
303 return NULL;
304
306 buf =
GNUNET_malloc (strlen (path) + strlen (binary) + 1 + 1);
307 pos = path;
308 while (NULL != (
end = strchr (pos,
310 {
312 sprintf (buf,
313 "%s/%s",
314 pos,
315 binary);
318 {
322 return pos;
323 }
325 }
326 sprintf (buf,
327 "%s/%s",
328 pos,
329 binary);
332 {
336 return pos;
337 }
340 return NULL;
341}
342
343
351static char *
353{
355
362 return NULL;
363}
364
365
373static char *
375{
377
380#ifdef __linux__
381 if (NULL != (
ret = get_path_from_proc_maps (pd)))
383
387 if (NULL != (
ret = get_path_from_proc_exe (pd)))
389#endif
390#if DARWIN
391 if (NULL != (
ret = get_path_from_dyld_image ()))
393 if (NULL != (
ret = get_path_from_NSGetExecutablePath ()))
395#endif
399
401 "Could not determine installation path for %s. Set `%s' environment variable.\n",
404 return NULL;
405}
406
407
414static char *
416{
418
419#ifdef __linux__
420 if (NULL != (
ret = get_path_from_proc_exe (pd)))
422#endif
423#if DARWIN
424 if (NULL != (
ret = get_path_from_NSGetExecutablePath ()))
426#endif
427
429}
430
431
432char *
435{
436 size_t n;
437 char *dirname;
438 char *execpath = NULL;
439 char *tmp;
440 char *multiarch;
441 char *libdir;
442 int isbasedir;
443
444
447
448
449
450 if (NULL == execpath)
452 if (NULL == execpath)
453 return NULL;
454
455 n = strlen (execpath);
456 if (0 == n)
457 {
458
460 return NULL;
461 }
462
464 execpath[--n] = '\0';
465
466 isbasedir = 1;
467 if ((n > 6) && ((0 == strcasecmp (&execpath[n - 6], "/lib32")) ||
468 (0 == strcasecmp (&execpath[n - 6], "/lib64"))))
469 {
472 {
473
474 execpath[n - 6] = '\0';
475 n -= 6;
476 }
477 else
478 isbasedir = 0;
479 }
480 else if ((n > 4) && ((0 == strcasecmp (&execpath[n - 4], "/bin")) ||
481 (0 == strcasecmp (&execpath[n - 4], "/lib"))))
482 {
483
484 execpath[n - 4] = '\0';
485 n -= 4;
486 }
487 multiarch = NULL;
488 if (NULL != (libdir = strstr (execpath, "/lib/")))
489 {
490
491
492 multiarch = &libdir[5];
493 if (NULL == strchr (multiarch, '/'))
494 libdir[0] =
495 '\0';
496 else
497 multiarch =
498 NULL;
499 }
500
502 execpath[--n] = '\0';
503 switch (dirkind)
504 {
508 break;
509
512 break;
513
515 if (isbasedir)
516 {
518 "%s%s%s%s%s%s%s",
519 execpath,
522 (NULL != multiarch) ? multiarch : "",
527 {
529 return tmp;
530 }
532 tmp = NULL;
533 dirname = NULL;
534 if (4 == sizeof(void *))
535 {
541 "%s%s",
542 execpath,
543 dirname);
544 }
545 if (8 == sizeof(void *))
546 {
552 "%s%s",
553 execpath,
554 dirname);
555 }
556
557 if ((NULL != tmp) &&
561 {
564 return tmp;
565 }
568 }
572 break;
573
579 break;
580
584 break;
585
589 break;
590
597 break;
598
600 if (isbasedir)
601 {
607 "%s%s%s%s",
608 execpath,
610 (NULL != multiarch) ? multiarch : "",
611 dirname);
615 true))
616 {
618 return tmp;
619 }
621 tmp = NULL;
622 dirname = NULL;
623 if (4 == sizeof(void *))
624 {
631 "%s%s",
632 execpath,
633 dirname);
634 }
635 if (8 == sizeof(void *))
636 {
643 "%s%s",
644 execpath,
645 dirname);
646 }
647 if ((NULL != tmp) &&
650 true)))
651 {
654 return tmp;
655 }
658 }
663 break;
664
665 default:
667 return NULL;
668 }
670 "%s%s",
671 execpath,
672 dirname);
675 return tmp;
676}
677
678
679char *
681 const char *progname)
682{
683 static char *cache;
684 char *libexecdir;
685 char *binary;
686
691 NULL,
692 NULL)))
694 if (NULL != cache)
695 libexecdir = cache;
696 else
699 if (NULL == libexecdir)
702 "%s%s",
703 libexecdir,
704 progname);
705 cache = libexecdir;
706 return binary;
707}
708
709
710char *
713 const char *progname)
714{
715 static char *cache;
716 char *binary = NULL;
717 char *path = NULL;
718 size_t path_len;
719
723 NULL,
724 NULL))
725 {
727 }
728 if (NULL != cache)
729 path = cache;
730 else
732 "PATHS",
733 "SUID_BINARY_PATH",
734 &path);
735 if ( (NULL == path) ||
736 (0 == strlen (path)) )
737 {
738 if (NULL != path)
740 cache = NULL;
742 progname);
743 }
744 path_len = strlen (path);
746 "%s%s%s",
747 path,
750 progname);
751 cache = path;
752 return binary;
753}
754
755
758 bool check_suid,
759 const char *params)
760{
761 struct stat statbuf;
763 char *pf;
764
768 NULL,
769 NULL)) ||
770 (0 == strncmp (binary, "./", 2)) )
771 {
773 }
774 else
775 {
778 {
780 "%s/%s",
782 binary);
785 }
786 }
787
789 {
791 _ (
"Could not find binary `%s' in PATH!\n"),
792 binary);
794 }
796 X_OK))
797 {
799 "access",
803 }
804
805 if (0 == getuid ())
806 {
807
810 }
811
813 &statbuf))
814 {
816 "stat",
820 }
821 if (check_suid)
822 {
823 (void) params;
824 if ( (0 != (statbuf.st_mode & S_ISUID)) &&
825 (0 == statbuf.st_uid) )
826 {
829 }
831 _ (
"Binary `%s' exists, but is not SUID\n"),
833
834 }
837}
838
839
840
#define bindtextdomain(Domainname, Dirname)
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * dir
Set to the directory where runtime files are stored.
static int end
Set if we are to shutdown all services (including ARM).
static char * line
Desired phone line (string to be converted to a hash).
static const struct GNUNET_CRYPTO_PrivateKey zero
Public key of all zeros.
static struct GNUNET_OS_Process * p
Helper process we started.
#define GNUNET_AGPL_URL
NOTE: You MUST adjust this URL to point to the location of a publicly accessible repository (or TGZ) ...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
void GNUNET_OS_init(const char *package_name, const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem for the given project data and package.
enum GNUNET_GenericReturnValue GNUNET_OS_check_helper_binary(const char *binary, bool check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
char * GNUNET_OS_get_suid_binary_path(const struct GNUNET_OS_ProjectData *pd, const struct GNUNET_CONFIGURATION_Handle *cfg, const char *progname)
Given the name of a helper, service or daemon binary construct the full path to the binary using the ...
GNUNET_OS_InstallationPathKind
Possible installation paths to request.
char * GNUNET_OS_get_libexec_binary_path(const struct GNUNET_OS_ProjectData *pd, const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
@ GNUNET_OS_IPK_SELF_PREFIX
Return the installation directory of this application, not the one of the overall GNUnet installation...
@ GNUNET_OS_IPK_ICONDIR
Return the prefix of the path with application icons (share/icons/).
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
@ GNUNET_OS_IPK_DOCDIR
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
@ GNUNET_OS_IPK_BINDIR
Return the directory where the program binaries are installed.
@ GNUNET_OS_IPK_LIBEXECDIR
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
enum GNUNET_GenericReturnValue GNUNET_STRINGS_path_is_absolute(const char *filename, int can_be_uri, int *r_is_uri, char **r_uri_scheme)
Check whether filename is absolute or not, and if it's an URI.
static char * os_get_exec_path(const struct GNUNET_OS_ProjectData *pd)
get the path to current app's bin/
#define LOG_STRERROR_FILE(kind, syscall, filename)
static const struct GNUNET_OS_ProjectData default_pd
Default project data used for installation path detection for GNUnet (core).
static char * get_path_from_GNUNET_PREFIX(const struct GNUNET_OS_ProjectData *pd)
Try to obtain the installation path using the "GNUNET_PREFIX" environment variable.
static char * os_get_gnunet_path(const struct GNUNET_OS_ProjectData *pd)
get the path to GNUnet bin/ or lib/, preferring the lib/ path
static char * get_path_from_PATH(const char *binary)
Return the actual path to a file found in the current PATH environment variable.
static unsigned int size
Size of the "table".
Project-specific data used to help the OS subsystem find installation paths.
const char * binary_name
Name of a project-specific binary that should be in "$PREFIX/bin/".
const char * env_varname
Name of an environment variable that can be used to override installation path detection,...
const char * env_varname_alt
Alternative name of an environment variable that can be used to override installation path detection,...
const char * libname
Name of a library that is installed in the "lib/" directory of the project, such as "libgnunetutil".
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".