Folling wtays suggestion, I was going to start using xmlDocDump, to avoid a symlink attack on the temporary registry ...

Original commit message from CVS:
Folling wtays suggestion, I was going to start using xmlDocDump, to
avoid a symlink attack on the temporary registry file.  Unfortunately,
xmlDocDump doesn't give any indication whether its successful, so I've
#ifdefed this out and left the original in place.  Since the tmp file
is in /etc/gstreamer, this should be okay for the moment, but I shall
ask the libxml people to add some way of getting the success value of
DocDump so we can use that in future.
This commit is contained in:
Richard Boulton 2001-01-07 16:14:35 +00:00
parent 01c946b685
commit 9b1970967e

View file

@ -20,9 +20,11 @@
* Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <gst/gst.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
@ -88,7 +90,7 @@ static int make_dir(const char * dirname) {
return !mkdir(dirname, mode);
}
void check_dir(const char * dirname) {
static void check_dir(const char * dirname) {
if (!is_dir(dirname)) {
if (!make_dir(dirname)) {
g_print("Cannot create GStreamer registry directory `%s'",
@ -98,6 +100,32 @@ void check_dir(const char * dirname) {
}
}
static void save_registry(const char *destfile) {
#if 0
FILE *fp;
fp = fopen (destfile, "w");
if (!fp) {
g_print("Cannot open `%s' to save new registry to.", destfile);
error_perm();
}
// FIXME: no way to check success of xmlDocDump, which is why
// this piece of code is ifdefed out.
xmlDocDump(fp, doc);
if (!fclose(fp)) {
g_print("Cannot close `%s' having saved new registry.", destfile);
error_perm();
}
#else
if (xmlSaveFile(destfile, doc) <= 0) {
g_print("Cannot save new registry to `%s'", destfile);
error_perm();
}
#endif
}
int main(int argc,char *argv[])
{
xmlDocPtr doc;
@ -119,11 +147,7 @@ int main(int argc,char *argv[])
gst_plugin_save_thyself(doc->root);
// Save the registry to a tmp file.
if (xmlSaveFile(GLOBAL_REGISTRY_FILE_TMP, doc) <= 0) {
g_print("Cannot save new registry `%s'",
GLOBAL_REGISTRY_FILE_TMP);
error_perm();
}
save_registry(GLOBAL_REGISTRY_FILE_TMP);
// Make the tmp file live.
move_file(GLOBAL_REGISTRY_FILE_TMP, GLOBAL_REGISTRY_FILE);