Coverage Report

Created: 2026-05-24 07:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/graphicsmagick/magick/confirm_access.c
Line
Count
Source
1
/*
2
% Copyright (C) 2009 GraphicsMagick Group
3
%
4
% This program is covered by multiple licenses, which are described in
5
% Copyright.txt. You should have received a copy of Copyright.txt with this
6
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
7
%
8
*/
9

10
/*
11
  Include declarations.
12
*/
13
#include "magick/studio.h"
14
#include "magick/confirm_access.h"
15
#include "magick/utility.h"
16

17
/*
18
  Global declarations.
19
*/
20
static ConfirmAccessHandler
21
  confirm_access_handler = (ConfirmAccessHandler) NULL;
22

23
/*
24
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25
%                                                                             %
26
%                                                                             %
27
%                                                                             %
28
%   M a g i c k C o n f i r m A c c e s s                                     %
29
%                                                                             %
30
%                                                                             %
31
%                                                                             %
32
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33
%
34
%  MagickConfirmAccess() calls the access confirmation handler method with
35
%  parameters which describe the requested access mode and path/URL, as well
36
%  as an ExceptionInfo structure to update with any error information.  A
37
%  user-provided callback (set by MagickSetConfirmAccessHandler()) is
38
%  invoked.  If the callback returns MagickFail, then this function also
39
%  returns MagickFail, which is intended to determine if the operation may
40
%  continue.  The callback is expected to report the reason access is denied
41
%  by filling out the ExceptionInfo structure.  If the callback fails to do
42
%  so, then a generic "access denied" error is reported.
43
%
44
%  The format of the MagickConfirmAccess method is:
45
%
46
%      MagickPassFail MagickConfirmAccess(const ConfirmAccessMode mode,
47
%                                         const char *path,
48
%                                         ExceptionInfo *exception)
49
%
50
%  A description of each parameter follows:
51
%
52
%    o mode: The type of access to be performed.
53
%
54
%    o path: The local path or URL requested to be accessed.
55
%
56
%    o exception: Return any errors or warnings in this structure.
57
%
58
*/
59
MagickExport MagickPassFail
60
MagickConfirmAccess(const ConfirmAccessMode mode,
61
                    const char *path,
62
                    ExceptionInfo *exception)
63
549k
{
64
549k
  MagickPassFail
65
549k
    status;
66
67
549k
  assert(path != (const char *) NULL);
68
549k
  status=MagickPass;
69
549k
  if (confirm_access_handler != (ConfirmAccessHandler) NULL)
70
0
    status=(*confirm_access_handler)(mode,path,exception);
71
549k
  return(status);
72
549k
}
73

74
/*
75
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
%                                                                             %
77
%                                                                             %
78
%                                                                             %
79
%   M a g i c k S e t C o n f i r m A c c e s s H a n d l e r                 %
80
%                                                                             %
81
%                                                                             %
82
%                                                                             %
83
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
%
85
%  MagickSetConfirmAccessHandler() sets the access confirmation handler to
86
%  the specified method and returns the previous access confirmation handler.
87
%  This access confirmation handler is used to "approve" access to files and
88
%  URLs.  If the handler returns MagickFalse, then access is denied.  This
89
%  mechanism may be used to enforce security policies and/or may be used to
90
%  monitor file and URL accesses.
91
%
92
%  The format of the MagickSetConfirmAccessHandler method is:
93
%
94
%      ConfirmAccessHandler MagickSetConfirmAccessHandler(ConfirmAccessHandler handler)
95
%
96
%  A description of each parameter follows:
97
%
98
%    o handler: Specifies a pointer to a method to handle access confirmation.
99
%
100
%
101
*/
102
MagickExport ConfirmAccessHandler
103
MagickSetConfirmAccessHandler(ConfirmAccessHandler handler)
104
0
{
105
0
  ConfirmAccessHandler
106
0
    previous_handler;
107
108
0
  previous_handler=confirm_access_handler;
109
0
  confirm_access_handler=handler;
110
0
  return(previous_handler);
111
0
}