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 }
533 "%s%s%s%s%s",
534 execpath,
540 {
542 return tmp;
543 }
545 dirname = NULL;
546 if (4 == sizeof(void *))
547 {
553 "%s%s",
554 execpath,
555 dirname);
556 }
557 if (8 == sizeof(void *))
558 {
564 "%s%s",
565 execpath,
566 dirname);
567 }
568
569 if ((NULL != tmp) &&
573 {
576 return tmp;
577 }
580 }
584 break;
585
591 break;
592
596 break;
597
601 break;
602
609 break;
610
612 if (isbasedir)
613 {
619 "%s%s%s%s",
620 execpath,
622 (NULL != multiarch) ? multiarch : "",
623 dirname);
627 true))
628 {
630 return tmp;
631 }
633 tmp = NULL;
634 dirname = NULL;
635 if (4 == sizeof(void *))
636 {
643 "%s%s",
644 execpath,
645 dirname);
646 }
647 if (8 == sizeof(void *))
648 {
655 "%s%s",
656 execpath,
657 dirname);
658 }
659 if ((NULL != tmp) &&
662 true)))
663 {
666 return tmp;
667 }
670 }
675 break;
676
677 default:
679 return NULL;
680 }
682 "%s%s",
683 execpath,
684 dirname);
687 return tmp;
688}
689
690
691char *
693 const char *progname)
694{
695 static char *cache;
696 char *libexecdir;
697 char *binary;
698
703 NULL,
704 NULL)))
706 if (NULL != cache)
707 libexecdir = cache;
708 else
711 if (NULL == libexecdir)
714 "%s%s",
715 libexecdir,
716 progname);
717 cache = libexecdir;
718 return binary;
719}
720
721
722char *
725 const char *progname)
726{
727 static char *cache;
728 char *binary = NULL;
729 char *path = NULL;
730 size_t path_len;
731
735 NULL,
736 NULL))
737 {
739 }
740 if (NULL != cache)
741 path = cache;
742 else
744 "PATHS",
745 "SUID_BINARY_PATH",
746 &path);
747 if ( (NULL == path) ||
748 (0 == strlen (path)) )
749 {
750 if (NULL != path)
752 cache = NULL;
754 progname);
755 }
756 path_len = strlen (path);
758 "%s%s%s",
759 path,
762 progname);
763 cache = path;
764 return binary;
765}
766
767
770 bool check_suid,
771 const char *params)
772{
773 struct stat statbuf;
775 char *pf;
776
780 NULL,
781 NULL)) ||
782 (0 == strncmp (binary, "./", 2)) )
783 {
785 }
786 else
787 {
790 {
792 "%s/%s",
794 binary);
797 }
798 }
799
801 {
803 _ (
"Could not find binary `%s' in PATH!\n"),
804 binary);
806 }
808 X_OK))
809 {
811 "access",
815 }
816
817 if (0 == getuid ())
818 {
819
822 }
823
825 &statbuf))
826 {
828 "stat",
832 }
833 if (check_suid)
834 {
835 (void) params;
836 if ( (0 != (statbuf.st_mode & S_ISUID)) &&
837 (0 == statbuf.st_uid) )
838 {
841 }
843 _ (
"Binary `%s' exists, but is not SUID\n"),
845
846 }
849}
850
851
852
#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_BlindablePrivateKey zero
Public key of all zeros.
static struct GNUNET_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".