Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/unotools/securityoptions.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
#pragma once
20
21
#include <unotools/unotoolsdllapi.h>
22
#include <sal/types.h>
23
#include <rtl/ustring.hxx>
24
#include <vector>
25
#include <unordered_map>
26
27
/*-************************************************************************************************************
28
    @short          collect information about security features
29
    @ATTENTION      This class is partially threadsafe.
30
31
    @devstatus      ready to use
32
*//*-*************************************************************************************************************/
33
34
namespace SvtSecurityOptions
35
{
36
    enum class EOption
37
    {
38
        SecureUrls,
39
        DocWarnSaveOrSend,
40
        DocWarnSigning,
41
        DocWarnPrint,
42
        DocWarnCreatePdf,
43
        DocWarnRemoveEditingTimeInfo,
44
        DocWarnRemovePersonalInfo,
45
        DocWarnKeepRedlineInfo,
46
        DocWarnKeepDocUserInfo,
47
        DocWarnKeepNoteAuthorDateInfo,
48
        DocWarnKeepDocVersionInfo,
49
        DocKeepPrinterSettings,
50
        DocWarnRecommendPassword,
51
        MacroSecLevel,
52
        MacroTrustedAuthors,
53
        CtrlClickHyperlink,
54
        BlockUntrustedRefererLinks,
55
        DisableActiveContent
56
    };
57
58
    struct Certificate
59
    {
60
        OUString SubjectName;
61
        OUString SerialNumber;
62
        OUString RawData;
63
64
        bool operator==(const Certificate& other) const
65
0
        {
66
0
            return SubjectName == other.SubjectName && SerialNumber == other.SerialNumber && RawData == other.RawData;
67
0
        }
68
    };
69
70
71
    /*-****************************************************************************************************
72
        @short      returns readonly state
73
        @descr      It can be called to get information about the readonly state of a provided item.
74
        @param      "eOption", specify, which item is queried
75
        @return     <TRUE/> if item is readonly; <FALSE/> otherwise
76
77
        @onerror    No error should occur!
78
    *//*-*****************************************************************************************************/
79
80
    UNOTOOLS_DLLPUBLIC bool IsReadOnly( EOption eOption );
81
82
    /*-****************************************************************************************************
83
        @short      interface methods to get and set value of config key "org.openoffice.Office.Common/Security/Scripting/SecureURL"
84
        @descr      These value displays the list of all trustworthy URLs.
85
                    zB.:    file:/                  => All scripts from the local file system including a LAN;
86
                            private:explorer        => Scripts from the Explorer;
87
                            private:help            => Scripts in the help system;
88
                            private:newmenu         => Scripts that are executed by the commands File-New and AutoPilot;
89
                            private:schedule        => Scripts of  the scheduler;
90
                            private:searchfolder    => Scripts of the searchfolder;
91
                            private:user            => Scripts that are entered in the URL field.
92
        @param      "seqURLList", new values to set it in configuration.
93
        @return     The values which represent current state of internal variable.
94
95
        @onerror    No error should occur!
96
    *//*-*****************************************************************************************************/
97
98
    UNOTOOLS_DLLPUBLIC std::vector< OUString >  GetSecureURLs();
99
    UNOTOOLS_DLLPUBLIC void SetSecureURLs( std::vector< OUString >&& seqURLList );
100
101
    /*-****************************************************************************************************
102
            @short      interface methods to get and set value of config key "org.openoffice.Office.Common/Security/Scripting/MacroSecurityLevel"
103
            @descr      These value determines how StarOffice Basic scripts should be handled.
104
                        It exist 3 different modes:
105
                            0 = never execute
106
                            1 = from list
107
                            2 = always execute
108
109
            @ATTENTION  These methods don't check for valid or invalid values!
110
                        Our configuration server can do it ... but these implementation don't get any notifications
111
                        about wrong commits ...!
112
                        => If you set an invalid value - nothing will be changed. The information will lost.
113
114
            @seealso    enum EBasicSecurityMode
115
116
            @param      "eMode" to set new mode ... Value must defined as an enum of type EBasicSecurityMode!
117
            @return     An enum value, which present current mode.
118
119
            @onerror    No error should occur!
120
        *//*-*****************************************************************************************************/
121
122
    UNOTOOLS_DLLPUBLIC sal_Int32 GetMacroSecurityLevel();
123
    UNOTOOLS_DLLPUBLIC void SetMacroSecurityLevel( sal_Int32 _nLevel );
124
125
    UNOTOOLS_DLLPUBLIC bool IsMacroDisabled();
126
127
    /**
128
       Check whether the given uri is either no dangerous macro-execution
129
       URI at all or else the given referer is a trusted source.
130
    */
131
    UNOTOOLS_DLLPUBLIC bool isSecureMacroUri(OUString const & uri, OUString const & referer);
132
133
    /**
134
       Check whether the given referer URI is untrusted, and links
135
       originating from it should not be accessed.
136
     */
137
    UNOTOOLS_DLLPUBLIC bool isUntrustedReferer(OUString const & referer);
138
139
    /**
140
       Check whether the given uri is a trusted location.
141
    */
142
    UNOTOOLS_DLLPUBLIC bool isTrustedLocationUri(OUString const & uri);
143
144
    UNOTOOLS_DLLPUBLIC bool isTrustedLocationUriForUpdatingLinks(OUString const & uri);
145
146
    UNOTOOLS_DLLPUBLIC std::vector< Certificate > GetTrustedAuthors();
147
    UNOTOOLS_DLLPUBLIC void SetTrustedAuthors( const std::vector< Certificate >& rAuthors );
148
149
    // for bool options only!
150
    UNOTOOLS_DLLPUBLIC bool        IsOptionSet     ( EOption eOption                   );
151
    UNOTOOLS_DLLPUBLIC void        SetOption       ( EOption eOption, bool bValue      );
152
153
} // namespace SvtSecurityOptions
154
155
// map personal info strings, e.g. authors to 1, 2, 3... for removing personal info
156
157
class UNOTOOLS_DLLPUBLIC SvtSecurityMapPersonalInfo
158
{
159
    std::unordered_map< OUString, size_t > aInfoIDs;
160
public:
161
    size_t GetInfoID( const OUString& sPersonalInfo );
162
};
163
164
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */