33 | 33 |
#include <limits.h>
|
34 | 34 |
#include <errno.h>
|
35 | 35 |
#include <unistd.h>
|
|
36 |
#include <time.h>
|
36 | 37 |
|
37 | 38 |
#include "gpgrt-int.h"
|
38 | 39 |
|
|
662 | 663 |
}
|
663 | 664 |
|
664 | 665 |
|
665 | |
/* Implementation of the "user" command. ARG is the context. ARGS is
|
666 | |
* a non-empty string which this function is allowed to modify. */
|
|
666 |
/* Make sure the username field is filled. Return 0 on success. */
|
667 | 667 |
static int
|
668 | |
handle_meta_user (gpgrt_argparse_t *arg, unsigned int alternate, char *args)
|
669 | |
{
|
670 | |
(void)alternate;
|
671 | |
|
|
668 |
assure_username (gpgrt_argparse_t *arg)
|
|
669 |
{
|
672 | 670 |
if (!arg->internal->username)
|
673 | 671 |
{
|
674 | 672 |
arg->internal->username = _gpgrt_getusername ();
|
|
683 | 681 |
return ARGPARSE_PERMISSION_ERROR;
|
684 | 682 |
}
|
685 | 683 |
}
|
686 | |
|
|
684 |
return 0;
|
|
685 |
}
|
|
686 |
|
|
687 |
|
|
688 |
/* Implementation of the "user" command. ARG is the context. ARGS is
|
|
689 |
* a non-empty string which this function is allowed to modify. */
|
|
690 |
static int
|
|
691 |
handle_meta_user (gpgrt_argparse_t *arg, unsigned int alternate, char *args)
|
|
692 |
{
|
|
693 |
int rc;
|
|
694 |
|
|
695 |
(void)alternate;
|
|
696 |
|
|
697 |
rc = assure_username (arg);
|
|
698 |
if (rc)
|
|
699 |
return rc;
|
687 | 700 |
|
688 | 701 |
arg->internal->user_seen = 1;
|
689 | 702 |
if (*args == '*' && !args[1])
|
|
756 | 769 |
static int
|
757 | 770 |
handle_meta_echo (gpgrt_argparse_t *arg, unsigned int alternate, char *args)
|
758 | 771 |
{
|
|
772 |
int rc = 0;
|
|
773 |
char *p, *pend;
|
|
774 |
|
759 | 775 |
if (alternate)
|
760 | |
_gpgrt_log_info ("%s\n", args);
|
|
776 |
_gpgrt_log_info ("%s", "");
|
761 | 777 |
else
|
762 | |
_gpgrt_log_info ("%s:%u: %s\n",
|
763 | |
arg->internal->confname, arg->lineno, args);
|
764 | |
return 0;
|
|
778 |
_gpgrt_log_info ("%s:%u: ", arg->internal->confname, arg->lineno);
|
|
779 |
|
|
780 |
while (*args)
|
|
781 |
{
|
|
782 |
p = strchr (args, '$');
|
|
783 |
if (!p)
|
|
784 |
{
|
|
785 |
_gpgrt_log_printf ("%s", args);
|
|
786 |
break;
|
|
787 |
}
|
|
788 |
*p = 0;
|
|
789 |
_gpgrt_log_printf ("%s", args);
|
|
790 |
if (p[1] == '$')
|
|
791 |
{
|
|
792 |
_gpgrt_log_printf ("$");
|
|
793 |
args = p+2;
|
|
794 |
continue;
|
|
795 |
}
|
|
796 |
if (p[1] != '{')
|
|
797 |
{
|
|
798 |
_gpgrt_log_printf ("$");
|
|
799 |
args = p+1;
|
|
800 |
continue;
|
|
801 |
}
|
|
802 |
pend = strchr (p+2, '}');
|
|
803 |
if (!pend) /* No closing brace. */
|
|
804 |
{
|
|
805 |
_gpgrt_log_printf ("$");
|
|
806 |
args = p+1;
|
|
807 |
continue;
|
|
808 |
}
|
|
809 |
p += 2;
|
|
810 |
*pend = 0;
|
|
811 |
args = pend+1;
|
|
812 |
if (!strcmp (p, "user"))
|
|
813 |
{
|
|
814 |
rc = assure_username (arg);
|
|
815 |
if (rc)
|
|
816 |
goto leave;
|
|
817 |
_gpgrt_log_printf ("%s", arg->internal->username);
|
|
818 |
}
|
|
819 |
else if (!strcmp (p, "file"))
|
|
820 |
_gpgrt_log_printf ("%s", arg->internal->confname);
|
|
821 |
else if (!strcmp (p, "line"))
|
|
822 |
_gpgrt_log_printf ("%u", arg->lineno);
|
|
823 |
else if (!strcmp (p, "epoch"))
|
|
824 |
_gpgrt_log_printf ("%lu", (unsigned long)time (NULL));
|
|
825 |
}
|
|
826 |
|
|
827 |
leave:
|
|
828 |
_gpgrt_log_printf ("\n");
|
|
829 |
return rc;
|
765 | 830 |
}
|
766 | 831 |
|
767 | 832 |
|