1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_stoc.hxx"
26
27 #include <stdio.h>
28
29 #include <sal/main.h>
30 #include <osl/diagnose.h>
31 #include <osl/socket.hxx>
32 #include <rtl/string.hxx>
33 #include <rtl/ustrbuf.hxx>
34 #include <uno/current_context.hxx>
35
36 #include <cppuhelper/implbase1.hxx>
37 #include <cppuhelper/bootstrap.hxx>
38 #include <cppuhelper/access_control.hxx>
39
40 #include <com/sun/star/lang/XComponent.hpp>
41 #include <com/sun/star/uno/XCurrentContext.hpp>
42
43 #include <com/sun/star/io/FilePermission.hpp>
44
45 #define USER_CREDS "access-control.user-credentials"
46 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
47
48
49 using namespace ::osl;
50 using namespace ::rtl;
51 using namespace ::cppu;
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::uno;
54
55 //--------------------------------------------------------------------------------------------------
localhost(OUString const & addition)56 static OUString localhost( OUString const & addition ) SAL_THROW( () )
57 {
58 static OUString ip;
59 if (! ip.getLength())
60 {
61 // dns lookup
62 SocketAddr addr;
63 SocketAddr::resolveHostname( OUSTR("localhost"), addr );
64 ::oslSocketResult rc = ::osl_getDottedInetAddrOfSocketAddr( addr.getHandle(), &ip.pData );
65 if (::osl_Socket_Ok != rc)
66 fprintf(stdout, "### cannot resolve localhost!" );
67 }
68 OUStringBuffer buf( 48 );
69 buf.append( ip );
70 buf.append( addition );
71 return buf.makeStringAndClear();
72 }
73
74 //--------------------------------------------------------------------------------------------------
dispose(Reference<XInterface> const & x)75 static inline void dispose( Reference< XInterface > const & x )
76 {
77 Reference< lang::XComponent > xComp( x, UNO_QUERY );
78 if (xComp.is())
79 {
80 xComp->dispose();
81 }
82 }
83 //==================================================================================================
84 class user_CurrentContext
85 : public ImplHelper1< XCurrentContext >
86 {
87 oslInterlockedCount m_refcount;
88
89 Reference< XCurrentContext > m_xDelegate;
90 Any m_userId;
91
92 public:
user_CurrentContext(Reference<XCurrentContext> const & xDelegate,OUString const & userId)93 inline user_CurrentContext(
94 Reference< XCurrentContext > const & xDelegate,
95 OUString const & userId )
96 SAL_THROW( () )
97 : m_refcount( 0 )
98 , m_xDelegate( xDelegate )
99 , m_userId( makeAny( userId ) )
100 {}
101
102 // XInterface impl
103 virtual void SAL_CALL acquire()
104 throw ();
105 virtual void SAL_CALL release()
106 throw ();
107
108 // XCurrentContext impl
109 virtual Any SAL_CALL getValueByName( OUString const & name );
110 };
111 //__________________________________________________________________________________________________
acquire()112 void user_CurrentContext::acquire()
113 throw ()
114 {
115 ::osl_incrementInterlockedCount( &m_refcount );
116 }
117 //__________________________________________________________________________________________________
release()118 void user_CurrentContext::release()
119 throw ()
120 {
121 if (! ::osl_decrementInterlockedCount( &m_refcount ))
122 {
123 delete this;
124 }
125 }
126 //__________________________________________________________________________________________________
getValueByName(OUString const & name)127 Any user_CurrentContext::getValueByName( OUString const & name )
128 {
129 if (name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(USER_CREDS ".id") ))
130 {
131 return m_userId;
132 }
133 else if (m_xDelegate.is())
134 {
135 return m_xDelegate->getValueByName( name );
136 }
137 else
138 {
139 return Any();
140 }
141 }
142
143 // prepends line number
144 #define CHECK( check, negative_test ) \
145 { \
146 try \
147 { \
148 if (negative_test) \
149 { \
150 bool thrown = true; \
151 try \
152 { \
153 check; \
154 thrown = false; \
155 } \
156 catch (RuntimeException &) \
157 { \
158 } \
159 if (! thrown) \
160 { \
161 throw RuntimeException( \
162 OUSTR("expected RuntimeException upon check!"), Reference< XInterface >() ); \
163 } \
164 } \
165 else \
166 { \
167 check; \
168 } \
169 } \
170 catch (RuntimeException & exc) \
171 { \
172 OUStringBuffer buf( 64 ); \
173 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("[line ") ); \
174 buf.append( (sal_Int32)__LINE__ ); \
175 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] ") ); \
176 buf.append( exc.Message ); \
177 throw RuntimeException( buf.makeStringAndClear(), Reference< XInterface >() ); \
178 } \
179 }
180
181 /*
182 grant
183 {
184 permission com.sun.star.io.FilePermission "file:///usr/bin/ *", "read";
185 permission com.sun.star.io.FilePermission "file:///tmp/-", "read,write";
186 permission com.sun.star.io.FilePermission "file:///etc/profile", "read";
187
188 permission com.sun.star.security.RuntimePermission "DEF";
189
190 permission com.sun.star.connection.SocketPermission "127.0.0.1:-1023", "resolve, connect, listen";
191 permission com.sun.star.connection.SocketPermission "localhost:1024-", "accept, connect, listen, resolve,";
192 permission com.sun.star.connection.SocketPermission "*.sun.com:1024-", "resolve";
193 };
194 */
check_defaults_pos(AccessControl & ac,bool invert=false)195 static void check_defaults_pos( AccessControl & ac, bool invert = false )
196 {
197 // positive tests
198 CHECK( ac.checkFilePermission( OUSTR("file:///usr/bin/bla"), OUSTR("read") ), invert );
199 CHECK( ac.checkFilePermission( OUSTR("file:///tmp/bla"), OUSTR("read,write") ), invert );
200 CHECK( ac.checkFilePermission( OUSTR("file:///tmp/path/path/bla"), OUSTR("write") ), invert );
201 CHECK( ac.checkFilePermission( OUSTR("file:///etc/profile"), OUSTR("read") ), invert );
202 CHECK( ac.checkRuntimePermission( OUSTR("DEF") ), invert );
203 CHECK( ac.checkSocketPermission( OUSTR("localhost:1024"), OUSTR("connect") ), invert );
204 CHECK( ac.checkSocketPermission( OUSTR("localhost:65535"), OUSTR("resolve") ), invert );
205 CHECK( ac.checkSocketPermission( localhost(OUSTR(":2048")), OUSTR("accept,listen") ), invert );
206 CHECK( ac.checkSocketPermission( localhost(OUSTR(":1024-")), OUSTR("accept,connect,listen,resolve") ), invert );
207 CHECK( ac.checkSocketPermission( OUSTR("localhost:-1023"), OUSTR("resolve,listen,connect") ), invert );
208 CHECK( ac.checkSocketPermission( OUSTR("jl-1036.germany.sun.com:1024-"), OUSTR("resolve") ), invert );
209 }
check_defaults_neg(AccessControl & ac,bool invert=false)210 static void check_defaults_neg( AccessControl & ac, bool invert = false )
211 {
212 // negative tests
213 CHECK( ac.checkFilePermission( OUSTR("file:///usr/tmp"), OUSTR("read") ), !invert );
214 CHECK( ac.checkFilePermission( OUSTR("file:///"), OUSTR("read") ), !invert );
215 CHECK( ac.checkFilePermission( OUSTR("file:///usr/bin"), OUSTR("read") ), !invert );
216 CHECK( ac.checkFilePermission( OUSTR("file:///usr/bin/bla"), OUSTR("write") ), !invert );
217 CHECK( ac.checkFilePermission( OUSTR("file:///usr/bin/bla"), OUSTR("execute") ), !invert );
218 CHECK( ac.checkFilePermission( OUSTR("file:///usr/bin/path/bla"), OUSTR("read") ), !invert );
219 CHECK( ac.checkFilePermission( OUSTR("file:///tmp"), OUSTR("read") ), !invert );
220 CHECK( ac.checkFilePermission( OUSTR("file:///tmp/"), OUSTR("read") ), !invert );
221 CHECK( ac.checkFilePermission( OUSTR("file:///tm"), OUSTR("read") ), !invert );
222 CHECK( ac.checkFilePermission( OUSTR("file:///etc/profile"), OUSTR("write") ), !invert );
223 CHECK( ac.checkFilePermission( OUSTR("file:///etc/profile/bla"), OUSTR("read") ), !invert );
224 CHECK( ac.checkFilePermission( OUSTR("file:///etc/blabla"), OUSTR("read,write,execute") ), !invert );
225 CHECK( ac.checkFilePermission( OUSTR("file:///home/root"), OUSTR("read,write,execute") ), !invert );
226 CHECK( ac.checkFilePermission( OUSTR("file:///root"), OUSTR("read,write,execute") ), !invert );
227 CHECK( ac.checkFilePermission( OUSTR("file:///root"), OUSTR("delete") ), !invert );
228 CHECK( ac.checkFilePermission( OUSTR("file:///root"), OUString() ), !invert );
229 CHECK( ac.checkRuntimePermission( OUSTR("ROOT") ), !invert );
230 CHECK( ac.checkSocketPermission( OUSTR("localhost:1023"), OUSTR("accept") ), !invert );
231 CHECK( ac.checkSocketPermission( OUSTR("localhost:123-"), OUSTR("accept") ), !invert );
232 CHECK( ac.checkSocketPermission( localhost(OUSTR(":-1023")), OUSTR("accept") ), !invert );
233 CHECK( ac.checkSocketPermission( OUSTR("localhost:-1023"), OUSTR("accept,resolve") ), !invert );
234 CHECK( ac.checkSocketPermission( OUSTR("sun.com:1024-"), OUSTR("resolve") ), !invert );
235 }
236
237 /*
238 grant user "dbo"
239 {
240 permission com.sun.star.io.FilePermission "file:///home/dbo/-", "read,write";
241 permission com.sun.star.io.FilePermission "-", "read,write";
242 permission com.sun.star.io.FilePermission "file:///usr/local/dbo/ *", "read";
243
244 permission com.sun.star.security.RuntimePermission "DBO";
245
246 permission com.sun.star.connection.SocketPermission "dbo-1:1024-", "listen";
247 permission com.sun.star.connection.SocketPermission "dbo-11081:-1023", "resolve";
248 permission com.sun.star.connection.SocketPermission "dbo-11081:18", "listen";
249 permission com.sun.star.connection.SocketPermission "dbo-11081:20-24", "listen";
250 permission com.sun.star.connection.SocketPermission "dbo-11081", "connect";
251 };
252 */
check_dbo_pos(AccessControl & ac,bool invert=false)253 static void check_dbo_pos( AccessControl & ac, bool invert = false )
254 {
255 check_defaults_pos( ac, invert );
256 // positive tests
257 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/bla"), OUSTR("read") ), invert );
258 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/bla"), OUSTR("write") ), invert );
259 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/bla"), OUSTR("read,write") ), invert );
260 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/path/bla"), OUSTR("read,write") ), invert );
261 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/path/path/bla"), OUSTR("read,write") ), invert );
262 CHECK( ac.checkFilePermission( OUSTR("file:///usr/local/dbo/*"), OUSTR("read") ), invert );
263 CHECK( ac.checkFilePermission( OUSTR("file:///usr/local/dbo/bla"), OUSTR("read") ), invert );
264 CHECK( ac.checkRuntimePermission( OUSTR("DBO") ), invert );
265 CHECK( ac.checkSocketPermission( OUSTR("dbo-1:1024-"), OUSTR("listen") ), invert );
266 CHECK( ac.checkSocketPermission( OUSTR("dbo-1:2048-3122"), OUSTR("listen") ), invert );
267 CHECK( ac.checkSocketPermission( OUSTR("dbo-1:2048-"), OUSTR("listen") ), invert );
268 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081:-1023"), OUSTR("resolve") ), invert );
269 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081:20-1023"), OUSTR("resolve") ), invert );
270 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081:18"), OUSTR("listen") ), invert );
271 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081:20-24"), OUSTR("listen") ), invert );
272 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081:22"), OUSTR("listen") ), invert );
273 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081"), OUSTR("connect") ), invert );
274 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081:22"), OUSTR("connect") ), invert );
275 }
check_dbo_neg(AccessControl & ac,bool invert=false)276 static void check_dbo_neg( AccessControl & ac, bool invert = false )
277 {
278 check_defaults_neg( ac, invert );
279 // negative tests
280 CHECK( ac.checkFilePermission( OUSTR("file:///home/-"), OUSTR("read") ), !invert );
281 CHECK( ac.checkFilePermission( OUSTR("file:///home/jbu/bla"), OUSTR("read") ), !invert );
282 CHECK( ac.checkFilePermission( OUSTR("file:///home/jbu/bla"), OUSTR("write") ), !invert );
283 CHECK( ac.checkFilePermission( OUSTR("file:///home/jbu/bla"), OUSTR("read,write") ), !invert );
284 CHECK( ac.checkFilePermission( OUSTR("file:///home/jbu/path/bla"), OUSTR("read") ), !invert );
285 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/path/path/bla"), OUSTR("read,execute") ), !invert );
286 CHECK( ac.checkFilePermission( OUSTR("file:///usr/local/-"), OUSTR("read") ), !invert );
287 CHECK( ac.checkFilePermission( OUSTR("file:///usr/local/dbo/path/bla"), OUSTR("read") ), !invert );
288 CHECK( ac.checkFilePermission( OUSTR("file:///usr/local/dbo/path/path/bla"), OUSTR("read") ), !invert );
289 CHECK( ac.checkRuntimePermission( OUSTR("JBU") ), !invert );
290 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081"), OUSTR("listen") ), !invert );
291 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081:22"), OUSTR("accept") ), !invert );
292 CHECK( ac.checkSocketPermission( OUSTR("jbu-11096:22"), OUSTR("resolve") ), !invert );
293 }
294
295 /*
296 grant user "jbu"
297 {
298 permission com.sun.star.io.FilePermission "file:///home/jbu/-", "read,write";
299 permission com.sun.star.io.FilePermission "*", "read,write";
300
301 permission com.sun.star.security.RuntimePermission "JBU";
302
303 permission com.sun.star.connection.SocketPermission "jbu-11096","resolve";
304 };
305 */
check_jbu_pos(AccessControl & ac,bool invert=false)306 static void check_jbu_pos( AccessControl & ac, bool invert = false )
307 {
308 check_defaults_pos( ac, invert );
309 // positive tests
310 CHECK( ac.checkFilePermission( OUSTR("file:///home/jbu/bla"), OUSTR("read") ), invert );
311 CHECK( ac.checkFilePermission( OUSTR("file:///home/jbu/bla"), OUSTR("write") ), invert );
312 CHECK( ac.checkFilePermission( OUSTR("file:///home/jbu/bla"), OUSTR("read,write") ), invert );
313 CHECK( ac.checkFilePermission( OUSTR("file:///home/jbu/path/bla"), OUSTR("read,write") ), invert );
314 CHECK( ac.checkFilePermission( OUSTR("file:///home/jbu/path/path/bla"), OUSTR("read,write") ), invert );
315 CHECK( ac.checkRuntimePermission( OUSTR("JBU") ), invert );
316 CHECK( ac.checkSocketPermission( OUSTR("jbu-11096"), OUSTR("resolve") ), invert );
317 CHECK( ac.checkSocketPermission( OUSTR("jbu-11096:20-24"), OUSTR("resolve") ), invert );
318 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081.germany.sun.com:2048"), OUSTR("resolve") ), invert );
319 }
check_jbu_neg(AccessControl & ac,bool invert=false)320 static void check_jbu_neg( AccessControl & ac, bool invert = false )
321 {
322 check_defaults_neg( ac, invert );
323 // negative tests
324 CHECK( ac.checkFilePermission( OUSTR("file:///home/-"), OUSTR("read") ), !invert );
325 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/path/bla"), OUSTR("read") ), !invert );
326 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/path/path/bla"), OUSTR("read") ), !invert );
327 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/bla"), OUSTR("read") ), !invert );
328 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/bla"), OUSTR("write") ), !invert );
329 CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/bla"), OUSTR("read,write") ), !invert );
330 CHECK( ac.checkFilePermission( OUSTR("file:///usr/local/-"), OUSTR("read") ), !invert );
331 CHECK( ac.checkFilePermission( OUSTR("file:///usr/local/dbo/bla"), OUSTR("read") ), !invert );
332 CHECK( ac.checkFilePermission( OUSTR("file:///usr/local/dbo/path/path/bla"), OUSTR("read") ), !invert );
333 CHECK( ac.checkRuntimePermission( OUSTR("DBO") ), !invert );
334 CHECK( ac.checkSocketPermission( OUSTR("jbu-11096:20-24"), OUSTR("accept") ), !invert );
335 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081"), OUSTR("connect") ), !invert );
336 CHECK( ac.checkSocketPermission( OUSTR("dbo-11081.germany.sun.com"), OUSTR("connect") ), !invert );
337 }
338
339 /*
340 grant principal "root"
341 {
342 permission com.sun.star.security.AllPermission;
343 };
344 */
345 //==================================================================================================
check_root_pos(AccessControl & ac,bool invert=false)346 static void check_root_pos( AccessControl & ac, bool invert = false )
347 {
348 check_defaults_pos( ac, invert );
349 check_defaults_neg( ac, !invert );
350 check_dbo_pos( ac, invert );
351 check_dbo_neg( ac, !invert );
352 check_jbu_pos( ac, invert );
353 check_jbu_neg( ac, !invert );
354 // some more root positive
355 CHECK( ac.checkFilePermission( OUSTR("file:///etc/blabla"), OUSTR("read,write,execute") ), invert );
356 CHECK( ac.checkFilePermission( OUSTR("file:///home/root"), OUSTR("read,write,execute") ), invert );
357 CHECK( ac.checkFilePermission( OUSTR("file:///root"), OUSTR("read,write,execute") ), invert );
358 CHECK( ac.checkRuntimePermission( OUSTR("ROOT") ), invert );
359 }
360
361 //==================================================================================================
362 class acc_Restr
363 : public WeakImplHelper1< security::XAccessControlContext >
364 {
365 Any m_perm;
366
367 public:
368 inline acc_Restr( Any const & perm = Any() ) SAL_THROW( () )
369 : m_perm( perm )
370 {}
371
372 // XAccessControlContext impl
373 virtual void SAL_CALL checkPermission( Any const & perm );
374 };
375 //__________________________________________________________________________________________________
checkPermission(Any const & perm)376 void acc_Restr::checkPermission( Any const & perm )
377 {
378 if (perm != m_perm)
379 {
380 throw security::AccessControlException(
381 OUSTR("dyn violation!"), Reference< XInterface >(), perm );
382 }
383 }
384
385 typedef void (* t_action)( AccessControl &, Any const & arg );
386
387 //==================================================================================================
388 class Action
389 : public WeakImplHelper1< security::XAction >
390 {
391 t_action m_action;
392 AccessControl & m_ac;
393 Any m_arg;
394
395 public:
Action(t_action action,AccessControl & ac,Any const & arg=Any ())396 inline Action( t_action action, AccessControl & ac, Any const & arg = Any() ) SAL_THROW( () )
397 : m_action( action )
398 , m_ac( ac )
399 , m_arg( arg )
400 {}
401
402 // XAction impl
403 virtual Any SAL_CALL run();
404 };
405 //__________________________________________________________________________________________________
run()406 Any Action::run()
407 {
408 (*m_action)( m_ac, m_arg );
409 return Any();
410 }
411
412 //==================================================================================================
413 // static void restr_file_permissions( AccessControl & ac )
414 // {
415 // // running in dbo's domain
416 // /* permission com.sun.star.io.FilePermission "file:///home/dbo/-", ",,read , write "; */
417 // CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/bla"), OUSTR("read,write,execute") ), true );
418 // CHECK( ac.checkFilePermission( OUSTR("file:///home/dbo/bla"), OUSTR("read,write") ), false );
419 // }
420 //==================================================================================================
all_dbo_permissions(AccessControl & ac,Any const &)421 static void all_dbo_permissions( AccessControl & ac, Any const & )
422 {
423 check_dbo_pos( ac );
424 check_dbo_neg( ac );
425 }
426 //==================================================================================================
no_permissions(AccessControl & ac,Any const & arg)427 static void no_permissions( AccessControl & ac, Any const & arg )
428 {
429 check_dbo_pos( ac, true );
430 check_dbo_neg( ac );
431 // set privs to old dbo restr
432 Reference< security::XAccessControlContext > xContext;
433 OSL_VERIFY( arg >>= xContext );
434 ac->doPrivileged(
435 new Action( all_dbo_permissions, ac ),
436 xContext );
437 }
438 //==================================================================================================
check_dbo_dynamic(AccessControl & ac)439 static void check_dbo_dynamic( AccessControl & ac )
440 {
441 Any arg( makeAny( ac->getContext() ) );
442 ac->doRestricted(
443 new Action( no_permissions, ac, arg ),
444 new acc_Restr() );
445 }
446
SAL_IMPLEMENT_MAIN()447 SAL_IMPLEMENT_MAIN()
448 {
449 try
450 {
451 // single-user test
452 Reference< XComponentContext > xContext( defaultBootstrap_InitialComponentContext(
453 OUSTR("../../test/security/test_security_singleuser.ini") ) );
454 {
455 ::fprintf( stderr, "[security test] single-user checking dbo..." );
456 AccessControl ac( xContext );
457 check_dbo_pos( ac );
458 check_dbo_neg( ac );
459 check_dbo_dynamic( ac );
460 ::fprintf( stderr, "dbo checked.\n" );
461 }
462
463 // multi-user test
464 dispose( xContext );
465 xContext = defaultBootstrap_InitialComponentContext(
466 OUSTR("../../test/security/test_security.ini") ); // UNO_AC=on
467 AccessControl ac( xContext );
468
469 {
470 // set up dbo current context
471 ContextLayer layer( new user_CurrentContext( getCurrentContext(), OUSTR("dbo") ) );
472 ::fprintf( stderr, "[security test] multi-user checking dbo..." );
473 check_dbo_pos( ac );
474 check_dbo_neg( ac );
475 check_dbo_dynamic( ac );
476 ::fprintf( stderr, "dbo checked.\n" );
477 }
478 {
479 // set up jbu current context
480 ContextLayer layer( new user_CurrentContext( getCurrentContext(), OUSTR("jbu") ) );
481 ::fprintf( stderr, "[security test] multi-user checking jbu..." );
482 check_jbu_pos( ac );
483 check_jbu_neg( ac );
484 ::fprintf( stderr, "jbu checked.\n" );
485 }
486 {
487 // set up root current context
488 ContextLayer layer( new user_CurrentContext( getCurrentContext(), OUSTR("root") ) );
489 ::fprintf( stderr, "[security test] multi-user checking root..." );
490 check_root_pos( ac );
491 ::fprintf( stderr, "root checked.\n" );
492 }
493 {
494 // set up unknown guest user current context => default permissions
495 ContextLayer layer( new user_CurrentContext( getCurrentContext(), OUSTR("guest") ) );
496 ::fprintf( stderr, "[security test] multi-user checking guest..." );
497 check_defaults_pos( ac );
498 check_defaults_neg( ac );
499 ::fprintf( stderr, "guest checked.\n" );
500 }
501
502 dispose( xContext );
503 ::fprintf( stderr, "security test succeeded.\n" );
504 return 0;
505 }
506 catch (Exception & exc)
507 {
508 OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
509 ::fprintf( stderr, "[security test] error: %s!\n", str.getStr() );
510 return 1;
511 }
512 }
513