1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* sb_l10n.c -- exec_policy based localization support.
*
* Copyright (C) 2008 Nokia Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libsb2.h"
#include "exported.h"
static void check_textdomain(const char *);
char *bindtextdomain_gate(char *(*realfn)(const char *, const char *),
const char *realfn_name, const char *domainname, const char *dirname)
{
mapping_results_t res;
const char *mapped_dirname = dirname;
char *result = NULL;
clear_mapping_results_struct(&res);
if (dirname != NULL) {
sbox_map_path(realfn_name, dirname, 0, &res);
assert(res.mres_result_path != NULL);
mapped_dirname = res.mres_result_path;
SB_LOG(SB_LOGLEVEL_DEBUG, "binding domain %s to %s",
domainname, mapped_dirname);
}
result = (*realfn)(domainname, mapped_dirname);
free_mapping_results(&res);
return (result);
}
static void check_textdomain(const char *domainname)
{
/*
* We read back current bindings for given domainname and
* call bindtextdomain() which then goes into our gate
* function that maps the path if exec policy says so.
*/
(void) bindtextdomain(domainname, bindtextdomain(domainname, NULL));
}
/*ARGSUSED*/
char *textdomain_gate(char *(*realfn)(const char *), const char *realfn_name,
const char *domainname)
{
(void)realfn_name;
check_textdomain(domainname);
return (*realfn)(domainname);
}
/*ARGSUSED*/
char *dgettext_gate(char *(*realfn)(const char *, const char *),
const char *realfn_name, const char *domainname, const char *msgid)
{
(void)realfn_name;
check_textdomain(domainname);
return (*realfn)(domainname, msgid);
}
/*ARGSUSED*/
char *dcgettext_gate(char *(*realfn)(const char *, const char *, int),
const char *realfn_name, const char *domainname, const char *msgid,
int category)
{
(void)realfn_name;
check_textdomain(domainname);
return (*realfn)(domainname, msgid, category);
}
/*ARGSUSED*/
char *dngettext_gate(char *(*realfn)(const char *, const char *, const char *,
unsigned long int n), const char *realfn_name,
const char *domainname, const char *msgid,
const char *msgid_plural, unsigned long int n)
{
(void)realfn_name;
check_textdomain(domainname);
return (*realfn)(domainname, msgid, msgid_plural, n);
}
/*ARGSUSED*/
char *dcngettext_gate(char *(*realfn)(const char *, const char *, const char *,
unsigned long int, int), const char *realfn_name,
const char *domainname, const char *msgid,
const char *msgid_plural, unsigned long int n, int category)
{
(void)realfn_name;
check_textdomain(domainname);
return (*realfn)(domainname, msgid, msgid_plural, n, category);
}
|