From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:08 +0000 (-0700) Subject: Add linuxDeploymentUtilities to libDeployPkg X-Git-Tag: stable-10.2.0~489 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=258e66b6a4e8cade7d3f3a9464958d9063cd286c;p=thirdparty%2Fopen-vm-tools.git Add linuxDeploymentUtilities to libDeployPkg --- diff --git a/open-vm-tools/libDeployPkg/Makefile.am b/open-vm-tools/libDeployPkg/Makefile.am index 4c32656cc..699b6a821 100644 --- a/open-vm-tools/libDeployPkg/Makefile.am +++ b/open-vm-tools/libDeployPkg/Makefile.am @@ -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 index 000000000..735036ce8 --- /dev/null +++ b/open-vm-tools/libDeployPkg/linuxDeploymentUtilities.c @@ -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 +#include +#include +#include +#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(®ex, 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(®ex, 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 index 000000000..56640f1ca --- /dev/null +++ b/open-vm-tools/libDeployPkg/linuxDeploymentUtilities.h @@ -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 + +bool IsCloudInitEnabled(const char* configFile); + +#endif //LINUXDEPLOYMENTUTILITIES_H_ +