]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Add linuxDeploymentUtilities to libDeployPkg
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:08 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:08 +0000 (11:23 -0700)
open-vm-tools/libDeployPkg/Makefile.am
open-vm-tools/libDeployPkg/linuxDeploymentUtilities.c [new file with mode: 0644]
open-vm-tools/libDeployPkg/linuxDeploymentUtilities.h [new file with mode: 0644]

index 4c32656ccb926cebaa1495773d5bf357b6d59cc7..699b6a8214ba1a9f4d218e26aad0b165c720011c 100644 (file)
@@ -31,6 +31,8 @@ libDeployPkg_la_SOURCES += mspackConfig.h
 libDeployPkg_la_SOURCES += mspackWrapper.c
 libDeployPkg_la_SOURCES += mspackWrapper.h
 libDeployPkg_la_SOURCES += processPosix.c
+libDeployPkg_la_SOURCES += linuxDeploymentUtilities.c
+libDeployPkg_la_SOURCES += linuxDeploymentUtilities.h
 libDeployPkg_la_SOURCES += toolsDeployPkg.h
 
 libDeployPkg_la_LDFLAGS =
diff --git a/open-vm-tools/libDeployPkg/linuxDeploymentUtilities.c b/open-vm-tools/libDeployPkg/linuxDeploymentUtilities.c
new file mode 100644 (file)
index 0000000..735036c
--- /dev/null
@@ -0,0 +1,71 @@
+/*********************************************************
+ * Copyright (C) 2016 VMware, Inc. All rights reserved.
+ *
+ * This program 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 version 2.1 and no later version.
+ *
+ * This program 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 Lesser GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
+ *
+ *********************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <regex.h>
+#include "linuxDeploymentUtilities.h"
+
+/**
+ *----------------------------------------------------------------------------
+ *
+ * IsCloudInitEnabled --
+ *
+ * Function to determine if cloud-init is enabled.
+ * Essentially it does
+ *  - read a cloud-init config file
+ *  - Find if a particular flag is enabled or disabled.
+ *
+ *  @param   [IN]  cloudFilePath path of the cloud-init config file
+ *  @returns TRUE if disable_vmware_customization is false and FALSE otherwise.
+ *
+ *----------------------------------------------------------------------------
+ **/
+bool
+IsCloudInitEnabled(const char *cloudFilePath)
+{
+   bool isEnabled = false;
+   FILE *cloudFile;
+   char line[256];
+   regex_t regex;
+   // Expected regex in cloud.cfg file
+   const char *cloudInitRegex = "^\\s*disable_vmware_customization\\s*:\\s*false\\s*$";
+   int reti = regcomp(&regex, cloudInitRegex, 0);
+   if (reti) {
+      return isEnabled;
+   }
+
+   // Read cloud.cfg file and find expected string.
+   cloudFile = fopen(cloudFilePath, "r");
+   if (cloudFile == NULL) {
+     return isEnabled;
+   }
+   while(fgets(line, sizeof(line), cloudFile)) {
+      if (!regexec(&regex, line, 0, NULL, 0)) {
+         isEnabled = true;
+         break;
+      }
+   }
+   if (ferror(cloudFile)) {
+      isEnabled = false;
+   }
+   fclose(cloudFile);
+
+   return isEnabled;
+}
diff --git a/open-vm-tools/libDeployPkg/linuxDeploymentUtilities.h b/open-vm-tools/libDeployPkg/linuxDeploymentUtilities.h
new file mode 100644 (file)
index 0000000..56640f1
--- /dev/null
@@ -0,0 +1,27 @@
+/*********************************************************
+ * Copyright (C) 2016 VMware, Inc. All rights reserved.
+ *
+ * This program 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 version 2.1 and no later version.
+ *
+ * This program 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 Lesser GNU General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
+ *
+ *********************************************************/
+
+#ifndef LINUXDEPLOYMENTUTILITIES_H_
+#define LINUXDEPLOYMENTUTILITIES_H_
+
+#include <stdbool.h>
+
+bool IsCloudInitEnabled(const char* configFile);
+
+#endif //LINUXDEPLOYMENTUTILITIES_H_
+