added wxFileConfig::SetUmask()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7329 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -241,10 +241,11 @@ actually enumerating them, but you will probably never need them.
|
||||
\helpref{Exists}{wxconfigbaseexists}\\
|
||||
\helpref{GetEntryType}{wxconfigbasegetentrytype}
|
||||
|
||||
\membersection{Miscellaneous accessors}
|
||||
\membersection{Miscellaneous functions}
|
||||
|
||||
\helpref{GetAppName}{wxconfigbasegetappname}\\
|
||||
\helpref{GetVendorName}{wxconfigbasegetvendorname}
|
||||
\helpref{GetVendorName}{wxconfigbasegetvendorname}\\
|
||||
\helpref{SetUmask}{wxfileconfigsetumask}
|
||||
|
||||
\membersection{Key access}
|
||||
|
||||
@@ -683,6 +684,19 @@ If on (default is off) all default values are written back to the config file.
|
||||
This allows the user to see what config options may be changed and is probably
|
||||
useful only for wxFileConfig.
|
||||
|
||||
\membersection{wxFileConfig::SetUmask}{wxfileconfigsetumask}
|
||||
|
||||
\func{void}{SetUmask}{\param{int }{mode}}
|
||||
|
||||
{\bf NB:} this function is not in the base wxConfigBase class but is only
|
||||
implemented in wxFileConfig. Moreover, this function is Unix-specific and
|
||||
doesn't do anything on other platforms.
|
||||
|
||||
SetUmask() allows to set the mode to be used for the config file creation.
|
||||
For example, to create a config file which is not readable by other users
|
||||
(useful if it stores some sensitive information, such as passwords), you
|
||||
should do {\tt SetUmask(0077)}.
|
||||
|
||||
\membersection{wxConfigBase::Write}\label{wxconfigbasewrite}
|
||||
|
||||
\func{bool}{Write}{\param{const wxString\& }{ key}, \param{const wxString\& }{
|
||||
|
@@ -149,6 +149,14 @@ public:
|
||||
// dtor will save unsaved data
|
||||
virtual ~wxFileConfig();
|
||||
|
||||
// under Unix, set the umask to be used for the file creation, do nothing
|
||||
// under other systems
|
||||
#ifdef __UNIX__
|
||||
void SetUmask(int mode) { m_umask = mode; }
|
||||
#else // !__UNIX__
|
||||
void SetUmask(int WXUNUSED(mode)) { }
|
||||
#endif // __UNIX__/!__UNIX__
|
||||
|
||||
// implement inherited pure virtual functions
|
||||
virtual void SetPath(const wxString& strPath);
|
||||
virtual const wxString& GetPath() const { return m_strPath; }
|
||||
@@ -244,6 +252,10 @@ private:
|
||||
ConfigGroup *m_pRootGroup, // the top (unnamed) group
|
||||
*m_pCurrentGroup; // the current group
|
||||
|
||||
#ifdef __UNIX__
|
||||
int m_umask; // the umask to use for file creation
|
||||
#endif // __UNIX__
|
||||
|
||||
public:
|
||||
WX_DEFINE_SORTED_ARRAY(ConfigEntry *, ArrayEntries);
|
||||
WX_DEFINE_SORTED_ARRAY(ConfigGroup *, ArrayGroups);
|
||||
|
@@ -54,6 +54,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
// headers needed for umask()
|
||||
#ifdef __UNIX__
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif // __UNIX__
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// macros
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -371,6 +377,8 @@ wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName,
|
||||
}
|
||||
}
|
||||
|
||||
SetUmask(-1);
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -767,6 +775,15 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */)
|
||||
if ( LineListIsEmpty() || !m_pRootGroup->IsDirty() || !m_strLocalFile )
|
||||
return TRUE;
|
||||
|
||||
#ifdef __UNIX__
|
||||
// set the umask if needed
|
||||
mode_t umaskOld = 0;
|
||||
if ( m_umask != -1 )
|
||||
{
|
||||
umaskOld = umask((mode_t)m_umask);
|
||||
}
|
||||
#endif // __UNIX__
|
||||
|
||||
wxTempFile file(m_strLocalFile);
|
||||
|
||||
if ( !file.IsOpened() ) {
|
||||
@@ -782,10 +799,9 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __WXMAC__
|
||||
return file.Commit();
|
||||
#else
|
||||
bool ret = file.Commit();
|
||||
|
||||
#ifdef __WXMAC__
|
||||
if ( ret )
|
||||
{
|
||||
FSSpec spec ;
|
||||
@@ -799,8 +815,17 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */)
|
||||
FSpSetFInfo( &spec , &finfo ) ;
|
||||
}
|
||||
}
|
||||
return ret ;
|
||||
#endif
|
||||
#endif // __WXMAC__
|
||||
|
||||
#ifdef __UNIX__
|
||||
// restore the old umask if we changed it
|
||||
if ( m_umask != -1 )
|
||||
{
|
||||
(void)umask(umaskOld);
|
||||
}
|
||||
#endif // __UNIX__
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user