2013-02-14 15:26:13 +04:00
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd .
Copyright 2010 Lennart Poettering
Copyright 2010 Harald Hoyer
systemd 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 .
systemd 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 systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
2014-07-14 05:10:38 +04:00
# include "util.h"
2014-12-27 20:46:36 +03:00
# include "selinux-util.h"
# include "fileio-label.h"
2013-02-14 15:26:13 +04:00
2013-04-02 22:31:42 +04:00
int write_string_file_atomic_label ( const char * fn , const char * line ) {
2013-02-14 15:26:13 +04:00
int r ;
2014-10-23 21:41:27 +04:00
r = mac_selinux_create_file_prepare ( fn , S_IFREG ) ;
2014-07-14 05:10:38 +04:00
if ( r < 0 )
2013-02-14 15:26:13 +04:00
return r ;
2014-10-03 16:58:40 +04:00
r = write_string_file_atomic ( fn , line ) ;
2013-02-14 15:26:13 +04:00
2014-10-23 21:41:27 +04:00
mac_selinux_create_file_clear ( ) ;
2013-02-14 15:26:13 +04:00
return r ;
}
int write_env_file_label ( const char * fname , char * * l ) {
int r ;
2014-10-23 21:41:27 +04:00
r = mac_selinux_create_file_prepare ( fname , S_IFREG ) ;
2014-07-14 05:10:38 +04:00
if ( r < 0 )
2013-02-14 15:26:13 +04:00
return r ;
2014-10-03 16:58:40 +04:00
r = write_env_file ( fname , l ) ;
2013-02-14 15:26:13 +04:00
2014-10-23 21:41:27 +04:00
mac_selinux_create_file_clear ( ) ;
2013-02-14 15:26:13 +04:00
return r ;
}
2014-07-14 05:10:38 +04:00
int fopen_temporary_label ( const char * target ,
const char * path , FILE * * f , char * * temp_path ) {
int r ;
2014-10-23 21:41:27 +04:00
r = mac_selinux_create_file_prepare ( target , S_IFREG ) ;
2014-07-14 05:10:38 +04:00
if ( r < 0 )
return r ;
r = fopen_temporary ( path , f , temp_path ) ;
2014-10-23 21:41:27 +04:00
mac_selinux_create_file_clear ( ) ;
2014-07-14 05:10:38 +04:00
return r ;
}