Ejemplo n.º 1
0
int Xen_domain(void)

{ FILE *fp;
  char buffer[CF_BUFSIZE];
  int sufficient = 0;

/* xen host will have "control_d" in /proc/xen/capabilities, xen guest will not */
if ((fp = fopen("/proc/xen/capabilities","r")) != NULL)
   {
   while (!feof(fp))
      {
      ReadLine(buffer,CF_BUFSIZE,fp);
      if (strstr(buffer,"control_d"))
         {
         AddClassToHeap("xen_dom0");
         sufficient = 1;
         }
      }
   if (sufficient < 1)
      {
      AddClassToHeap("xen_domu_pv");
      sufficient = 1;
      }
   }

return sufficient < 1 ? 1 : 0;
}
Ejemplo n.º 2
0
int debian_version(void) /* Andrew Stribblehill */
{
#define DEBIAN_VERSION_FILENAME "/etc/debian_version"
int major = -1; 
int release = -1;
char classname[CF_MAXVARSIZE] = "";
FILE *fp;

if ((fp = fopen(DEBIAN_VERSION_FILENAME,"r")) == NULL)
   {
   return 1;
   }

Verbose("Looking for Debian version...\n");
switch (fscanf(fp, "%d.%d", &major, &release))
    {
    case 2:
        Verbose("This appears to be a Debian %u.%u system.", major, release);
        snprintf(classname, CF_MAXVARSIZE, "debian_%u_%u", major, release);
        AddClassToHeap(classname);
        /* Fall-through */
    case 1:
        Verbose("This appears to be a Debian %u system.", major);
        snprintf(classname, CF_MAXVARSIZE, "debian_%u", major);
        AddClassToHeap(classname);
        break;
    case 0:
        Verbose("No Debian version number found.\n");
        fclose(fp);
        return 2;
    }
fclose(fp);
return 0;
}
Ejemplo n.º 3
0
void
SetDomainName(char *sp)           /* Bas van der Vlies */
{
    char fqn[CF_MAXVARSIZE];
    char *ptr;
    char buffer[CF_BUFSIZE];

    if (gethostname(fqn, sizeof(fqn)) != -1) {
        strcpy(g_vfqname, fqn);
        strcpy(buffer, g_vfqname);
        AddClassToHeap(CanonifyName(buffer));
        AddClassToHeap(CanonifyName(ToLowerStr(buffer)));

        if (strstr(fqn, ".")) {
            ptr = strchr(fqn, '.');
            strcpy(g_vdomain, ++ptr);
        }
    }

    if (strstr(g_vfqname, ".") == 0 
            && (strcmp(g_vdomain, CF_START_DOMAIN) != 0)) {

        strcat(g_vfqname, ".");
        strcat(g_vfqname, g_vdomain);
    }

    AddClassToHeap(CanonifyName(g_vdomain));
    DeleteClassFromHeap("undefined_domain");
}
Ejemplo n.º 4
0
void AddMultipleClasses(char *classlist)

{ char *sp, currentitem[CF_MAXVARSIZE],local[CF_MAXVARSIZE];
 
if ((classlist == NULL) || strlen(classlist) == 0)
   {
   return;
   }

memset(local,0,CF_MAXVARSIZE);
strncpy(local,classlist,CF_MAXVARSIZE-1);

Debug("AddMultipleClasses(%s)\n",local);

for (sp = local; *sp != '\0'; sp++)
   {
   memset(currentitem,0,CF_MAXVARSIZE);

   sscanf(sp,"%250[^.:,]",currentitem);

   sp += strlen(currentitem);
      
   if (IsHardClass(currentitem))
      {
      FatalError("cfengine: You cannot use -D to define a reserved class!");
      }

   AddClassToHeap(CanonifyName(currentitem));
   }
}
Ejemplo n.º 5
0
void
AddNetworkClass(char *netmask)
{
    struct in_addr ip,nm;
    char *sp;
    char nmbuf[CF_MAXVARSIZE], ipbuf[CF_MAXVARSIZE];

    /*
     * Has to differentiate between cases such as:
     *      192.168.101.1/24 -> 192.168.101   and
     *      192.168.101.1/26 -> 192.168.101.0
     * We still have the, um... 'interesting' Class C default Network Class
     * set by GetNameInfo()
     */

    /* This is also a convenient method to ensure valid dotted quad */
    if ((nm.s_addr = inet_addr(netmask)) != -1 &&
            (ip.s_addr = inet_addr(g_vipaddress)) != -1) {

        /* Will not work with IPv6 */
        ip.s_addr &= nm.s_addr;
        strcpy(ipbuf,inet_ntoa(ip));

        strcpy(nmbuf, inet_ntoa(nm));

        while( (sp = strrchr(nmbuf, '.')) && strcmp(sp, ".0") == 0 ) {
            *sp = 0;
            *strrchr(ipbuf, '.') = 0;
        }
        AddClassToHeap(CanonifyName(ipbuf));
    }
}
Ejemplo n.º 6
0
/* 
 * Whatever the manuals might say, you cannot get IPV6 interface
 * configuration from the ioctls. This seems to be implemented in a non
 * standard way across OSes BSDi has done getifaddrs(), solaris 8 has a
 * new ioctl, Stevens book shows the suggestion which has not been
 * implemented...
 */
void
GetV6InterfaceInfo(void)
{
    FILE *pp;
    char buffer[CF_BUFSIZE];

    Verbose("Trying to locate my IPv6 address\n");

    switch (g_vsystemhardclass) {
    case cfnt:
        /* NT cannot do this */
        break;
    default:
        if ((pp = cfpopen("/sbin/ifconfig -a", "r")) == NULL) {
            Verbose("Could not find interface info\n");
            return;
        }

        while (!feof(pp)) {
            fgets(buffer, CF_BUFSIZE, pp);

            if (StrStr(buffer, "inet6")) {
                struct Item *ip,*list = NULL;
                char *sp;

                list = SplitStringAsItemList(buffer, ' ');

                for (ip = list; ip != NULL; ip=ip->next) {
                    for (sp = ip->name; *sp != '\0'; sp++) {

                        /* Remove CIDR mask */
                        if (*sp == '/')  {
                            *sp = '\0';
                        }
                    }

                    if (IsIPV6Address(ip->name) &&
                            (strcmp(ip->name, "::1") != 0)) {

                        Verbose("Found IPv6 address %s\n", ip->name);
                        AppendItem(&g_ipaddresses, ip->name, "");
                        AddClassToHeap(CanonifyName(ip->name));

                    }
                }
                DeleteItemList(list);
            }
        }
        fclose(pp);
        break;
    }
}
Ejemplo n.º 7
0
int linux_slackware_version(char *filename)
{
int major = -1; 
int minor = -1; 
int release = -1;
char classname[CF_MAXVARSIZE] = "";
FILE *fp;

if ((fp = fopen(filename,"r")) == NULL)
   {
   return 1;
   }

Verbose("Looking for Slackware version...\n");
switch (fscanf(fp, "Slackware %d.%d.%d", &major, &minor, &release))
    {
    case 3:
        Verbose("This appears to be a Slackware %u.%u.%u system.", major, minor, release);
        snprintf(classname, CF_MAXVARSIZE, "slackware_%u_%u_%u", major, minor, release);
        AddClassToHeap(classname);
        /* Fall-through */
    case 2:
        Verbose("This appears to be a Slackware %u.%u system.", major, minor);
        snprintf(classname, CF_MAXVARSIZE, "slackware_%u_%u", major, minor);
        AddClassToHeap(classname);
        /* Fall-through */
    case 1:
        Verbose("This appears to be a Slackware %u system.", major);
        snprintf(classname, CF_MAXVARSIZE, "slackware_%u", major);
        AddClassToHeap(classname);
        break;
    case 0:
        Verbose("No Slackware version number found.\n");
        fclose(fp);
        return 2;
    }
fclose(fp);
return 0;
}
Ejemplo n.º 8
0
int VM_version(void)

{ FILE *fp;
  char *sp,buffer[CF_BUFSIZE],classbuf[CF_BUFSIZE],version[CF_BUFSIZE];
  struct stat statbuf;
  int major,minor,bug;
  int len = 0;
  int sufficient = 0;

/* VMware Server ESX >= 3 has version info in /proc */
if ((fp = fopen("/proc/vmware/version","r")) != NULL)
   {
        ReadLine(buffer,CF_BUFSIZE,fp);
        Chop(buffer);
        if (sscanf(buffer,"VMware ESX Server %d.%d.%d",&major,&minor,&bug) > 0)
           {
           snprintf(classbuf,CF_BUFSIZE,"VMware ESX Server %d",major);
           AddClassToHeap(CanonifyName(classbuf));
           snprintf(classbuf,CF_BUFSIZE,"VMware ESX Server %d.%d",major,minor);
           AddClassToHeap(CanonifyName(classbuf));
           snprintf(classbuf,CF_BUFSIZE,"VMware ESX Server %d.%d.%d",major,minor,bug);
           AddClassToHeap(CanonifyName(classbuf));
           sufficient = 1;
           }
        else if (sscanf(buffer,"VMware ESX Server %s",version) > 0)
           {
           snprintf(classbuf,CF_BUFSIZE,"VMware ESX Server %s",version);
           AddClassToHeap(CanonifyName(classbuf));
           sufficient = 1;
           }
        fclose(fp);
   }

/* Fall back to checking for other files */
if (sufficient < 1 && ((fp = fopen("/etc/vmware-release","r")) != NULL) ||
                       (fp = fopen("/etc/issue","r")) != NULL)
   {
        ReadLine(buffer,CF_BUFSIZE,fp);
        Chop(buffer);
        AddClassToHeap(CanonifyName(buffer));

        /* Strip off the release code name e.g. "(Dali)" */
        if ((sp = strchr(buffer,'(')) != NULL)
           {
           *sp = 0;
           Chop(buffer);
           AddClassToHeap(CanonifyName(buffer));
           }
        sufficient = 1;
        fclose(fp);
   }

return sufficient < 1 ? 1 : 0;
}
Ejemplo n.º 9
0
int linux_fedora_version(void)
{
#define FEDORA_ID "Fedora"

#define RELEASE_FLAG "release "

/* We are looking for one of the following strings...
 *
 * Fedora Core release 1 (Yarrow)
 * Fedora release 7 (Zodfoobar)
 */

#define FEDORA_REL_FILENAME "/etc/fedora-release"

FILE *fp;

/* The full string read in from fedora-release */
char relstring[CF_MAXVARSIZE];
char classbuf[CF_MAXVARSIZE];

/* Fedora */
char *vendor="";
/* Where the numerical release will be found */
char *release=NULL;

int major = -1;
char strmajor[CF_MAXVARSIZE];

/* Grab the first line from the file and then close it. */
 if ((fp = fopen(FEDORA_REL_FILENAME,"r")) == NULL)
    {
    return 1;
    }
 fgets(relstring, sizeof(relstring), fp);
 fclose(fp);
 
 Verbose("Looking for fedora core linux info...\n");
 
 /* First, try to grok the vendor */
 if(!strncmp(relstring, FEDORA_ID, strlen(FEDORA_ID)))
    {
    vendor = "fedora";
    }
 else
    {
    Verbose("Could not identify OS distro from %s\n", FEDORA_REL_FILENAME);
    return 2;
    }
 
 /* Now, grok the release.  We assume that all the strings will
  * have the word 'release' before the numerical release.
  */
 release = strstr(relstring, RELEASE_FLAG);
 if(release == NULL)
    {
    Verbose("Could not find a numeric OS release in %s\n",
     FEDORA_REL_FILENAME);
    return 2;
    }
 else
    {
    release += strlen(RELEASE_FLAG);
    if (sscanf(release, "%d", &major) == 1)
       {
       sprintf(strmajor, "%d", major);
       }
    }
 
 if (major != -1 && (strcmp(vendor,"") != 0))
    {
    classbuf[0] = '\0';
    strcat(classbuf, vendor);
    AddClassToHeap(classbuf);
    strcat(classbuf, "_");
    strcat(classbuf, strmajor);
    AddClassToHeap(classbuf);
    }
 
 return 0;
}
Ejemplo n.º 10
0
void
GetNameInfo(void)
{
    int i, found = false;
    char *sp, *sp2;
    time_t tloc;
    struct hostent *hp;
    struct sockaddr_in cin;
#ifdef AIX
    char real_version[_SYS_NMLN];
#endif
#ifdef IRIX
    char real_version[256]; /* see <sys/syssgi.h> */
#endif
#ifdef HAVE_SYSINFO
#ifdef SI_ARCHITECTURE
    long sz;
#endif
#endif

    Debug("GetNameInfo()\n");

    g_vfqname[0] = g_vuqname[0] = '\0';

    if (uname(&g_vsysname) == -1) {
        perror("uname ");
        FatalError("Uname couldn't get kernel name info!!\n");
    }

#ifdef AIX
    snprintf(real_version, _SYS_NMLN, "%.80s.%.80s",
            g_vsysname.version, g_vsysname.release);
    strncpy(g_vsysname.release, real_version, _SYS_NMLN);
#elif defined IRIX
/* This gets us something like `6.5.19m' rather than just `6.5'.  */
    syssgi (SGI_RELEASE_NAME, 256, real_version);
#endif

    for (sp = g_vsysname.sysname; *sp != '\0'; sp++) {
        *sp = ToLower(*sp);
    }

    for (sp = g_vsysname.machine; *sp != '\0'; sp++) {
        *sp = ToLower(*sp);
    }

    for (i = 0; g_classattributes[i][0] != '\0'; i++) {

        if (WildMatch(g_classattributes[i][0],
                    ToLowerStr(g_vsysname.sysname))) {

            if (WildMatch(g_classattributes[i][1], 
                        g_vsysname.machine)) {

                if (WildMatch(g_classattributes[i][2], 
                            g_vsysname.release)) {

                    if (g_underscore_classes) {
                        snprintf(g_vbuff, CF_BUFSIZE, "_%s", g_classtext[i]);
                        AddClassToHeap(g_vbuff);
                    } else {
                        AddClassToHeap(g_classtext[i]);
                    }
                    found = true;
                    g_vsystemhardclass = (enum classes) i;
                    break;
                }
            } else {
                Debug2("Cfengine: I recognize %s but not %s\n",
                        g_vsysname.sysname, g_vsysname.machine);
                    continue;
            }
        }
   }

    if ((sp = malloc(strlen(g_vsysname.nodename)+1)) == NULL) {
        FatalError("malloc failure in initialize()");
    }

    strcpy(sp, g_vsysname.nodename);
    SetDomainName(sp);

    /* Truncate fully qualified name */
    for (sp2=sp; *sp2 != '\0'; sp2++) {
        if (*sp2 == '.') {
            *sp2 = '\0';
            Debug("Truncating fully qualified hostname %s to %s\n",
                    g_vsysname.nodename,sp);
            break;
        }
    }

    g_vdefaultbinserver.name = sp;

    AddClassToHeap(CanonifyName(sp));


    if ((tloc = time((time_t *)NULL)) == -1) {
        printf("Couldn't read system clock\n");
    }

    if (g_verbose || g_debug || g_d2 || g_d3) {
        if (g_underscore_classes) {
            snprintf(g_vbuff, CF_BUFSIZE, "_%s", g_classtext[i]);
        } else {
            snprintf(g_vbuff, CF_BUFSIZE, "%s", g_classtext[i]);
        }

        if (g_iscfengine) {
            printf ("cfng: configuration agent (cfagent) - \n%s\n%s\n\n",
                    VERSION, g_copyright);
        } else {
            printf ("cfng: configuration server (cfservd) - \n%s\n%s\n\n",
                    VERSION, g_copyright);
        }

        printf ("------------------------------------------------------------------------\n\n");
        printf ("Host name is: %s\n", g_vsysname.nodename);
        printf ("Operating System Type is %s\n", g_vsysname.sysname);
        printf ("Operating System Release is %s\n", g_vsysname.release);
        printf ("Architecture = %s\n\n\n", g_vsysname.machine);
        printf ("Using internal soft-class %s for host %s\n\n",
                g_vbuff, g_classtext[g_vsystemhardclass]);
        printf ("The time is now %s\n\n", ctime(&tloc));
        printf ("------------------------------------------------------------------------\n\n");

    }

    sprintf(g_vbuff, "%d_bit", sizeof(long)*8);
    AddClassToHeap(g_vbuff);
    Verbose("Additional hard class defined as: %s\n", CanonifyName(g_vbuff));

    snprintf(g_vbuff, CF_BUFSIZE, "%s_%s", g_vsysname.sysname,
            g_vsysname.release);
    AddClassToHeap(CanonifyName(g_vbuff));

#ifdef IRIX
    /* 
     * Get something like `irix64_6_5_19m' defined as well as
     * `irix64_6_5'.  Just copying the latter into g_vsysname.release
     * wouldn't be backwards-compatible.
     */
    snprintf(g_vbuff, CF_BUFSIZE, "%s_%s", g_vsysname.sysname, real_version);
    AddClassToHeap(CanonifyName(g_vbuff));
#endif

    AddClassToHeap(CanonifyName(g_vsysname.machine));

    Verbose("Additional hard class defined as: %s\n",CanonifyName(g_vbuff));

    snprintf(g_vbuff, CF_BUFSIZE,"%s_%s", g_vsysname.sysname,
            g_vsysname.machine);
    AddClassToHeap(CanonifyName(g_vbuff));

    Verbose("Additional hard class defined as: %s\n",CanonifyName(g_vbuff));

    snprintf(g_vbuff, CF_BUFSIZE, "%s_%s_%s",
            g_vsysname.sysname, g_vsysname.machine, g_vsysname.release);

    AddClassToHeap(CanonifyName(g_vbuff));

    Verbose("Additional hard class defined as: %s\n", CanonifyName(g_vbuff));

#ifdef HAVE_SYSINFO
#ifdef SI_ARCHITECTURE
    sz = sysinfo(SI_ARCHITECTURE, g_vbuff, CF_BUFSIZE);
    if (sz == -1) {
        Verbose("cfagent internal: sysinfo returned -1\n");
    } else {
        AddClassToHeap(CanonifyName(g_vbuff));
        Verbose("Additional hard class defined as: %s\n", g_vbuff);
    }
#endif
#endif

    snprintf(g_vbuff, CF_BUFSIZE, "%s_%s_%s_%s",
            g_vsysname.sysname, g_vsysname.machine, g_vsysname.release,
            g_vsysname.version);

    if (strlen(g_vbuff) < CF_MAXVARSIZE-2) {
        g_varch = strdup(CanonifyName(g_vbuff));
    } else {

        Verbose("cfagent internal: $(arch) overflows CF_MAXVARSIZE! Truncating\n");
        g_varch = strdup(CanonifyName(g_vsysname.sysname));
    }

    snprintf(g_vbuff, CF_BUFSIZE, "%s_%s",
            g_vsysname.sysname, g_vsysname.machine);

    g_varch2 = strdup(CanonifyName(g_vbuff));

    AddClassToHeap(g_varch);

    Verbose("Additional hard class defined as: %s\n", g_varch);

    if (! found) {

        CfLog(cferror,"Cfengine: I don't understand "
                "what architecture this is!","");

    }

    strcpy(g_vbuff, "compiled_on_");
    strcat(g_vbuff, CanonifyName(AUTOCONF_SYSNAME));

    AddClassToHeap(CanonifyName(g_vbuff));

    Verbose("\nGNU autoconf class from compile time: %s\n\n", g_vbuff);

    /* Get IP address from nameserver */
    if ((hp = gethostbyname(g_vsysname.nodename)) == NULL) {
        return;
    } else {
        memset(&cin, 0, sizeof(cin));
        cin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;
        Verbose("Address given by nameserver: %s\n", inet_ntoa(cin.sin_addr));
        strcpy(g_vipaddress, inet_ntoa(cin.sin_addr));

        for (i=0; hp->h_aliases[i] != NULL; i++) {
            Debug("Adding alias %s..\n", hp->h_aliases[i]);
            AddClassToHeap(CanonifyName(hp->h_aliases[i]));
        }
    }
}
Ejemplo n.º 11
0
void
GetInterfaceInfo(void)
{
    int fd, len, i, j;
    struct ifreq ifbuf[512], ifr, *ifp;
    struct ifconf list;
    struct sockaddr_in *sin;
    struct hostent *hp;
    char *sp;
    char ip[CF_MAXVARSIZE];
    char name[CF_MAXVARSIZE];

    Debug("GetInterfaceInfo()\n");

    if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
        CfLog(cferror, "Couldn't open socket", "socket");
        exit(1);
    }

    list.ifc_len = sizeof(ifbuf);
    list.ifc_req = ifbuf;

#ifdef SIOCGIFCONF
    if (ioctl(fd, SIOCGIFCONF, &list) == -1 ||
            (list.ifc_len < (sizeof(struct ifreq))))
#else
    if (ioctl(fd, OSIOCGIFCONF, &list) == -1 ||
            (list.ifc_len < (sizeof(struct ifreq))))
#endif
    {
        CfLog(cferror, "Couldn't get interfaces", "ioctl");
        exit(1);
    }

    for (j = 0, len = 0, ifp = list.ifc_req; len < list.ifc_len;
            len+=SIZEOF_IFREQ(*ifp), j++, ifp=&ifbuf[j]) {
        if (ifp->ifr_addr.sa_family == 0) {
            continue;
        }

        Verbose("Interface %d: %s\n", j+1, ifp->ifr_name);
        if(g_underscore_classes) {
            snprintf(g_vbuff, CF_BUFSIZE, "_net_iface_%s",
                    CanonifyName(ifp->ifr_name));
        } else {
            snprintf(g_vbuff, CF_BUFSIZE, "net_iface_%s",
                    CanonifyName(ifp->ifr_name));
        }
        AddClassToHeap(g_vbuff);

        if (ifp->ifr_addr.sa_family == AF_INET) {
            strncpy(ifr.ifr_name, ifp->ifr_name, sizeof(ifp->ifr_name));

            if (ioctl(fd,SIOCGIFFLAGS,&ifr) == -1) {
                CfLog(cferror, "No such network device", "ioctl");
                close(fd);
                return;
            }

            /* 
             * Used to check if interface was "up" if ((ifr.ifr_flags &
             * IFF_UP) && !(ifr.ifr_flags & IFF_LOOPBACK)) Now check
             * whether it is configured ...
             */
            if ((ifr.ifr_flags & IFF_BROADCAST) &&
                    !(ifr.ifr_flags & IFF_LOOPBACK)) {
                sin=(struct sockaddr_in *)&ifp->ifr_addr;

                snprintf(name, CF_MAXVARSIZE-1, "ipv4[%s]",
                        CanonifyName(ifp->ifr_name));
                AddMacroValue(g_contextid, name, 
                        inet_ntoa(sin->sin_addr));

                if ((hp = gethostbyaddr((char *)&(sin->sin_addr.s_addr),
                            sizeof(sin->sin_addr.s_addr), AF_INET)) == NULL) {
                    Debug("Host information for %s not found\n",
                            inet_ntoa(sin->sin_addr));
                } else {

                    if (hp->h_name != NULL) {
                        Debug("Adding hostip %s..\n",
                                inet_ntoa(sin->sin_addr));
                        AddClassToHeap(CanonifyName(inet_ntoa(sin->sin_addr)));
                        Debug("Adding hostname %s..\n", hp->h_name);
                        AddClassToHeap(CanonifyName(hp->h_name));

                        for (i=0; hp->h_aliases[i] != NULL; i++) {
                            Debug("Adding alias %s..\n", hp->h_aliases[i]);
                            AddClassToHeap(CanonifyName(hp->h_aliases[i]));
                        }

                        /* Old style compat */
                        strcpy(ip,inet_ntoa(sin->sin_addr));
                        AppendItem(&g_ipaddresses, ip, "");

                        for (sp = ip+strlen(ip)-1; *sp != '.'; sp--) { }
                        *sp = '\0';
                        AddClassToHeap(CanonifyName(ip));

                        /* New style */
                        strcpy(ip, "ipv4_");
                        strcat(ip, inet_ntoa(sin->sin_addr));
                        AddClassToHeap(CanonifyName(ip));

                        for (sp = ip+strlen(ip)-1; (sp > ip); sp--) {
                            if (*sp == '.') {
                                *sp = '\0';
                                AddClassToHeap(CanonifyName(ip));
                            }
                        }
                    }
                }
            }
        }

        ifp = (struct ifreq *)((char *)ifp + SIZEOF_IFREQ(*ifp));
    }

    close(fd);
}
Ejemplo n.º 12
0
int linux_suse_version(void)
{
#define SUSE_REL_FILENAME "/etc/SuSE-release"
/* Check if it's a SuSE Enterprise version (all in lowercase) */
#define SUSE_SLES8_ID "suse sles-8"
#define SUSE_SLES_ID  "suse linux enterprise server"
#define SUSE_RELEASE_FLAG "linux "

/* The full string read in from SuSE-release */
char relstring[CF_MAXVARSIZE];
char classbuf[CF_MAXVARSIZE];
char vbuf[CF_BUFSIZE];

/* Where the numerical release will be found */
char *release=NULL;

int i,version;
int major = -1;
char strmajor[CF_MAXVARSIZE];
int minor = -1;
char strminor[CF_MAXVARSIZE];

FILE *fp;

 /* Grab the first line from the file and then close it. */

if ((fp = fopen(SUSE_REL_FILENAME,"r")) == NULL)
   {
   return 1;
   }

fgets(relstring, sizeof(relstring), fp);
Chop(relstring);
fclose(fp);
  
   /* Check if it's a SuSE Enterprise version  */

Verbose("Looking for SuSE enterprise info in \"%s\"\n",relstring);
 
 /* Convert relstring to lowercase to handle rename of SuSE to 
  * SUSE with SUSE 10.0. 
  */

for (i = 0; i < strlen(relstring); i++)
   {
   relstring[i] = tolower(relstring[i]);
   }

   /* Check if it's a SuSE Enterprise version (all in lowercase) */

if (!strncmp(relstring, SUSE_SLES8_ID, strlen(SUSE_SLES8_ID)))
   {
   classbuf[0] = '\0';
   strcat(classbuf, "SLES8");
   AddClassToHeap(classbuf);
   }
else
   {
   for (version = 9; version < 13; version++)
      {
      snprintf(vbuf,CF_BUFSIZE,"%s %d ",SUSE_SLES_ID,version);
      Debug("Checking for suse [%s]\n",vbuf);
      
      if (!strncmp(relstring, vbuf, strlen(vbuf)))
         {
         snprintf(classbuf,CF_MAXVARSIZE,"SLES%d",version);
         AddClassToHeap(classbuf);
         }
      }
   }
    
 /* Determine release version. We assume that the version follows
  * the string "SuSE Linux" or "SUSE LINUX".
  */

release = strstr(relstring, SUSE_RELEASE_FLAG);

if (release == NULL)
   {
   Verbose("Could not find a numeric OS release in %s\n",SUSE_REL_FILENAME);
   return 2;
   }
else
   {
   release += strlen(SUSE_RELEASE_FLAG);
   sscanf(release, "%d.%d", &major, &minor);
   sprintf(strmajor, "%d", major);
   sprintf(strminor, "%d", minor);
   }

if(major != -1 && minor != -1)
   {
   classbuf[0] = '\0';
   strcat(classbuf, "SuSE");
   AddClassToHeap(classbuf);
   strcat(classbuf, "_");
   strcat(classbuf, strmajor);
   AddClassToHeap(classbuf);
   strcat(classbuf, "_");
   strcat(classbuf, strminor);
   AddClassToHeap(classbuf);
   }

return 0;
}
Ejemplo n.º 13
0
int linux_redhat_version(void)
{
#define REDHAT_ID "Red Hat Linux"
#define REDHAT_AS_ID "Red Hat Enterprise Linux AS"
#define REDHAT_AS21_ID "Red Hat Linux Advanced Server"
#define REDHAT_ES_ID "Red Hat Enterprise Linux ES"
#define REDHAT_WS_ID "Red Hat Enterprise Linux WS"
#define REDHAT_C_ID "Red Hat Enterprise Linux Client"
#define REDHAT_S_ID "Red Hat Enterprise Linux Server"
#define MANDRAKE_ID "Linux Mandrake"
#define MANDRAKE_10_1_ID "Mandrakelinux"
#define WHITEBOX_ID "White Box Enterprise Linux"
#define CENTOS_ID "CentOS"
#define SCIENTIFIC_SL_ID "Scientific Linux SL"
#define SCIENTIFIC_CERN_ID "Scientific Linux CERN"
#define RELEASE_FLAG "release "

/* We are looking for one of the following strings...
 *
 * Red Hat Linux release 6.2 (Zoot)
 * Red Hat Linux Advanced Server release 2.1AS (Pensacola)
 * Red Hat Enterprise Linux AS release 3 (Taroon)
 * Red Hat Enterprise Linux WS release 3 (Taroon)
 * Red Hat Enterprise Linux Client release 5 (Tikanga)
 * Red Hat Enterprise Linux Server release 5 (Tikanga)
 * Linux Mandrake release 7.1 (helium)
 * Red Hat Enterprise Linux ES release 2.1 (Panama)
 * White Box Enterprise linux release 3.0 (Liberation)
 * Scientific Linux SL Release 4.0 (Beryllium)
 * CentOS release 4.0 (Final)
 */

#define RH_REL_FILENAME "/etc/redhat-release"

FILE *fp;

/* The full string read in from redhat-release */
char relstring[CF_MAXVARSIZE];
char classbuf[CF_MAXVARSIZE];

/* Red Hat, Mandrake */
char *vendor="";
/* as (Advanced Server, Enterprise) */
char *edition="";
/* Where the numerical release will be found */
char *release=NULL;
int i;
int major = -1;
char strmajor[CF_MAXVARSIZE];
int minor = -1;
char strminor[CF_MAXVARSIZE];

/* Grab the first line from the file and then close it. */
 if ((fp = fopen(RH_REL_FILENAME,"r")) == NULL)
    {
    return 1;
    }
 fgets(relstring, sizeof(relstring), fp);
 fclose(fp);
 
Verbose("Looking for redhat linux info in \"%s\"\n",relstring);
 
 /* First, try to grok the vendor and the edition (if any) */
 if(!strncmp(relstring, REDHAT_ES_ID, strlen(REDHAT_ES_ID)))
    {
    vendor = "redhat";
    edition = "es";
    }
 else if(!strncmp(relstring, REDHAT_WS_ID, strlen(REDHAT_WS_ID)))
    {
    vendor = "redhat";
    edition = "ws";
    }
 else if(!strncmp(relstring, REDHAT_WS_ID, strlen(REDHAT_WS_ID)))
    {
    vendor = "redhat";
    edition = "ws";
    }
 else if(!strncmp(relstring, REDHAT_AS_ID, strlen(REDHAT_AS_ID)) ||
  !strncmp(relstring, REDHAT_AS21_ID, strlen(REDHAT_AS21_ID)))
    {
    vendor = "redhat";
    edition = "as";
    }
 else if(!strncmp(relstring, REDHAT_S_ID, strlen(REDHAT_S_ID)))
    {
    vendor = "redhat";
    edition = "s";
    }
 else if(!strncmp(relstring, REDHAT_C_ID, strlen(REDHAT_C_ID)))
    {
    vendor = "redhat";
    edition = "c";
    }
 else if(!strncmp(relstring, REDHAT_ID, strlen(REDHAT_ID)))
    {
    vendor = "redhat";
    }
 else if(!strncmp(relstring, MANDRAKE_ID, strlen(MANDRAKE_ID)))
    {
    vendor = "mandrake";
    }
 else if(!strncmp(relstring, MANDRAKE_10_1_ID, strlen(MANDRAKE_10_1_ID)))
    {
    vendor = "mandrake";
    }
 else if(!strncmp(relstring, WHITEBOX_ID, strlen(WHITEBOX_ID)))
    {
    vendor = "whitebox";
    }
 else if(!strncmp(relstring, SCIENTIFIC_SL_ID, strlen(SCIENTIFIC_SL_ID)))
    {
    vendor = "scientific";
    edition = "sl";
    }
 else if(!strncmp(relstring, SCIENTIFIC_CERN_ID, strlen(SCIENTIFIC_CERN_ID)))
    {
    vendor = "scientific";
    edition = "cern";
    }
 else if(!strncmp(relstring, CENTOS_ID, strlen(CENTOS_ID)))
    {
    vendor = "centos";
    }
 else
    {
    Verbose("Could not identify OS distro from %s\n", RH_REL_FILENAME);
    return 2;
    }
 
 /* Now, grok the release.  For AS, we neglect the AS at the end of the
  * numerical release because we already figured out that it *is* AS
  * from the infomation above.  We assume that all the strings will
  * have the word 'release' before the numerical release.
  */

  /* Convert relstring to lowercase so that vendors like
     Scientific Linux don't fall through the cracks.
   */

 for (i = 0; i < strlen(relstring); i++)
    {
    relstring[i] = tolower(relstring[i]);
    }
 
 release = strstr(relstring, RELEASE_FLAG);
 if(release == NULL)
    {
    Verbose("Could not find a numeric OS release in %s\n",
     RH_REL_FILENAME);
    return 2;
    }
 else
    {
    release += strlen(RELEASE_FLAG);
    if (sscanf(release, "%d.%d", &major, &minor) == 2)
       {
       sprintf(strmajor, "%d", major);
       sprintf(strminor, "%d", minor);
       }
    /* red hat 9 is *not* red hat 9.0. 
     * and same thing with RHEL AS 3
     */
    else if (sscanf(release, "%d", &major) == 1)
       {
       sprintf(strmajor, "%d", major);
       minor = -2;
       }
    }
 
 if (major != -1 && minor != -1 && (strcmp(vendor,"") != 0))
    {
    classbuf[0] = '\0';
    strcat(classbuf, vendor);
    AddClassToHeap(classbuf);
    strcat(classbuf, "_");
    
    if (strcmp(edition,"") != 0)
       {
       strcat(classbuf, edition);
       AddClassToHeap(classbuf);
       strcat(classbuf, "_");
       }
    
    strcat(classbuf, strmajor);
    AddClassToHeap(classbuf);
    if (minor != -2)
       {
       strcat(classbuf, "_");
       strcat(classbuf, strminor);
       AddClassToHeap(classbuf);
       }
    }
 return 0;
}
Ejemplo n.º 14
0
void AddTimeClass(char *str)

{ int i;
  char buf2[10], buf3[10], buf4[10], buf5[10], buf[10], out[10];
  time_t now = time(NULL);
  struct tm *tmv = gmtime(&now);
  
snprintf(buf,9,"GMT_Hr%d\n",tmv->tm_hour);
AddClassToHeap(buf);

for (i = 0; i < 7; i++)
   {
   if (strncmp(DAYTEXT[i],str,3)==0)
      {
      AddClassToHeap(DAYTEXT[i]);
      break;
      }
   }

sscanf(str,"%*s %s %s %s %s",buf2,buf3,buf4,buf5);

/* Hours */

sscanf(buf4,"%[^:]",buf);
sprintf(out,"Hr%s",buf);
AddClassToHeap(out);
memset(VHR,0,3);
strncpy(VHR,buf,2); 

/* Minutes */

sscanf(buf4,"%*[^:]:%[^:]",buf);
sprintf(out,"Min%s",buf);
AddClassToHeap(out);
memset(VMINUTE,0,3);
strncpy(VMINUTE,buf,2); 
 
sscanf(buf,"%d",&i);

switch ((i / 5))
   {
   case 0: AddClassToHeap("Min00_05");
           break;
   case 1: AddClassToHeap("Min05_10");
           break;
   case 2: AddClassToHeap("Min10_15");
           break;
   case 3: AddClassToHeap("Min15_20");
           break;
   case 4: AddClassToHeap("Min20_25");
           break;
   case 5: AddClassToHeap("Min25_30");
           break;
   case 6: AddClassToHeap("Min30_35");
           break;
   case 7: AddClassToHeap("Min35_40");
           break;
   case 8: AddClassToHeap("Min40_45");
           break;
   case 9: AddClassToHeap("Min45_50");
           break;
   case 10: AddClassToHeap("Min50_55");
            break;
   case 11: AddClassToHeap("Min55_00");
            break;
   }

/* Add quarters */ 

switch ((i / 15))
   {
   case 0: AddClassToHeap("Q1");
           sprintf(out,"Hr%s_Q1",VHR);
    AddClassToHeap(out);
           break;
   case 1: AddClassToHeap("Q2");
           sprintf(out,"Hr%s_Q2",VHR);
    AddClassToHeap(out);
           break;
   case 2: AddClassToHeap("Q3");
           sprintf(out,"Hr%s_Q3",VHR);
    AddClassToHeap(out);
           break;
   case 3: AddClassToHeap("Q4");
           sprintf(out,"Hr%s_Q4",VHR);
    AddClassToHeap(out);
           break;
   }
 

/* Day */

sprintf(out,"Day%s",buf3);
AddClassToHeap(out);
memset(VDAY,0,3);
strncpy(VDAY,buf3,2);
 
/* Month */

for (i = 0; i < 12; i++)
   {
   if (strncmp(MONTHTEXT[i],buf2,3)==0)
      {
      AddClassToHeap(MONTHTEXT[i]);
      memset(VMONTH,0,4);
      strncpy(VMONTH,MONTHTEXT[i],3);
      break;
      }
   }

/* Year */

strcpy(VYEAR,buf5); 

sprintf(out,"Yr%s",buf5);
AddClassToHeap(out);
}
Ejemplo n.º 15
0
void IDClasses()

{ struct stat statbuf;
  char *sp;
  int i = 0;

AddClassToHeap("any");      /* This is a reserved word / wildcard */
 
snprintf(VBUFF,CF_BUFSIZE,"cfengine_%s",CanonifyName(VERSION));
AddClassToHeap(VBUFF);
 
for (sp = VBUFF+strlen(VBUFF); i < 2; sp--)
   {
   if (*sp == '_')
      {
      i++;
      *sp = '\0';
      AddClassToHeap(VBUFF);
      }
   }

#ifdef LINUX

/* {Mandrake,Fedora} has a symlink at /etc/redhat-release pointing to
 * /etc/{mandrake,fedora}-release, so we else-if around that
 */

if (stat("/etc/mandrake-release",&statbuf) != -1)
   {
   Verbose("This appears to be a mandrake system.\n");
   AddClassToHeap("Mandrake");
   linux_mandrake_version();
   }

else if (stat("/etc/fedora-release",&statbuf) != -1)
   {
   Verbose("This appears to be a fedora system.\n");
   AddClassToHeap("redhat");
   AddClassToHeap("fedora");
   linux_fedora_version();
   }

else if (stat("/etc/redhat-release",&statbuf) != -1)
   {
   Verbose("This appears to be a redhat system.\n");
   AddClassToHeap("redhat");
   linux_redhat_version();
   }

if (stat("/etc/generic-release",&statbuf) != -1)
   {
   Verbose("\nThis appears to be a sun cobalt system.\n");
   AddClassToHeap("SunCobalt");
   }

if (stat("/etc/SuSE-release",&statbuf) != -1)
   {
   Verbose("\nThis appears to be a SuSE system.\n");
   AddClassToHeap("SuSE");
   linux_suse_version();
   }

#define SLACKWARE_ANCIENT_VERSION_FILENAME "/etc/slackware-release"
#define SLACKWARE_VERSION_FILENAME "/etc/slackware-version"
if (stat(SLACKWARE_VERSION_FILENAME,&statbuf) != -1)
   {
   Verbose("\nThis appears to be a slackware system.\n");
   AddClassToHeap("slackware");
   linux_slackware_version(SLACKWARE_VERSION_FILENAME);
   }
else if (stat(SLACKWARE_ANCIENT_VERSION_FILENAME,&statbuf) != -1)
   {
   Verbose("\nThis appears to be an ancient slackware system.\n");
   AddClassToHeap("slackware");
   linux_slackware_version(SLACKWARE_ANCIENT_VERSION_FILENAME);
   }


if (stat("/etc/generic-release",&statbuf) != -1)
   {
   Verbose("\nThis appears to be a sun cobalt system.\n");
   AddClassToHeap("SunCobalt");
   }
 
if (stat("/etc/debian_version",&statbuf) != -1)
   {
   Verbose("\nThis appears to be a debian system.\n");
   AddClassToHeap("debian");
   debian_version();
   }

if (stat("/etc/UnitedLinux-release",&statbuf) != -1)
   {
   Verbose("\nThis appears to be a UnitedLinux system.\n");
   AddClassToHeap("UnitedLinux");
   }

if (stat("/etc/gentoo-release",&statbuf) != -1)
   {
   Verbose("\nThis appears to be a gentoo system.\n");
   AddClassToHeap("gentoo");
   }

lsb_version();

#endif

if (stat("/proc/vmware/version",&statbuf) != -1 ||
    stat("/etc/vmware-release",&statbuf) != -1)
   {
   Verbose("\nThis appears to be a VMware Server ESX system.\n");
   AddClassToHeap("VMware");
   VM_version();
   }
else if (stat("/etc/vmware",&statbuf) != -1)
   {
   if (S_ISDIR(statbuf.st_mode))
      {
      Verbose("\nThis appears to be a VMware xSX system.\n");
      AddClassToHeap("VMware");
      VM_version();
      }
   }

if (stat("/proc/xen/capabilities",&statbuf) != -1)
   {
   Verbose("\nThis appears to be a xen pv system.\n");
   AddClassToHeap("xen");
   Xen_domain();
   }
#ifdef XEN_CPUID_SUPPORT
else if (Xen_hv_check())
   {
   Verbose("\nThis appears to be a xen hv system.\n");
   AddClassToHeap("xen");
   AddClassToHeap("xen_domu_hv");
   }
#endif

}
Ejemplo n.º 16
0
int linux_mandrake_version(void)
{

/* We are looking for one of the following strings... */
#define MANDRAKE_ID "Linux Mandrake"
#define MANDRAKE_REV_ID "Mandrake Linux"
#define MANDRAKE_10_1_ID "Mandrakelinux"

#define RELEASE_FLAG "release "
#define MANDRAKE_REL_FILENAME "/etc/mandrake-release"

FILE *fp;

/* The full string read in from mandrake-release */
char relstring[CF_MAXVARSIZE];
char classbuf[CF_MAXVARSIZE];

/* I've never seen Mandrake-Move or the other 'editions', so
   I'm not going to try and support them here.  Contributions welcome. */

/* Where the numerical release will be found */
char *release=NULL;
char *vendor=NULL;
int major = -1;
char strmajor[CF_MAXVARSIZE];
int minor = -1;
char strminor[CF_MAXVARSIZE];

/* Grab the first line from the file and then close it. */
 if ((fp = fopen(MANDRAKE_REL_FILENAME,"r")) == NULL)
    {
    return 1;
    }
 fgets(relstring, sizeof(relstring), fp);
 fclose(fp);

 Verbose("Looking for Mandrake linux info in \"%s\"\n",relstring);

  /* Older Mandrakes had the 'Mandrake Linux' string in reverse order */
 if(!strncmp(relstring, MANDRAKE_ID, strlen(MANDRAKE_ID)))
    {
    vendor = "mandrake";
    }
 else if(!strncmp(relstring, MANDRAKE_REV_ID, strlen(MANDRAKE_REV_ID)))
    {
    vendor = "mandrake";
    }

 else if(!strncmp(relstring, MANDRAKE_10_1_ID, strlen(MANDRAKE_10_1_ID)))
    {
    vendor = "mandrake";
    }
 else
    {
    Verbose("Could not identify OS distro from %s\n", MANDRAKE_REL_FILENAME);
    return 2;
    }

 /* Now, grok the release. We assume that all the strings will
  * have the word 'release' before the numerical release.
  */
 release = strstr(relstring, RELEASE_FLAG);
 if(release == NULL)
    {
    Verbose("Could not find a numeric OS release in %s\n",
     MANDRAKE_REL_FILENAME);
    return 2;
    }
 else
    {
    release += strlen(RELEASE_FLAG);
    if (sscanf(release, "%d.%d", &major, &minor) == 2)
       {
       sprintf(strmajor, "%d", major);
       sprintf(strminor, "%d", minor);
       }
    else
       {
       Verbose("Could not break down release version numbers in %s\n",
       MANDRAKE_REL_FILENAME);
       }
    }

 if (major != -1 && minor != -1 && strcmp(vendor, ""))
    {
    classbuf[0] = '\0';
    strcat(classbuf, vendor);
    AddClassToHeap(classbuf);
    strcat(classbuf, "_");
    strcat(classbuf, strmajor);
    AddClassToHeap(classbuf);
    if (minor != -2)
       {
       strcat(classbuf, "_");
       strcat(classbuf, strminor);
       AddClassToHeap(classbuf);
       }
    }
 return 0;
}
Ejemplo n.º 17
0
int lsb_version(void)
{
#define LSB_RELEASE_COMMAND "lsb_release"

char classname[CF_MAXVARSIZE];
char *distrib  = NULL;
char *release  = NULL;
char *codename = NULL;
int major = 0;
int minor = 0;

char *path, *dir, *rest;
struct stat statbuf;

path = rest = strdup(getenv("PATH"));

if (strlen(path) == 0)
   {
   return 1;
   }

for (; dir = strsep(&rest, ":") ;)
    {
    snprintf(VBUFF, CF_BUFSIZE, "%s/" LSB_RELEASE_COMMAND, dir);
    if (stat(VBUFF,&statbuf) != -1)
        {
        free(path);
        path = strdup(VBUFF);

        Verbose("\nThis appears to be a LSB compliant system.\n");
        AddClassToHeap("lsb_compliant");
        break;
        }
    }

if (!dir)
    {
    free(path);
    return 1;
    }

if ((distrib  = lsb_release(path, "--id")) != NULL)
    {
    snprintf(classname, CF_MAXVARSIZE, "%s", distrib);
    AddClassToHeap(classname);

    if ((codename = lsb_release(path, "--codename")) != NULL)
        {
        snprintf(classname, CF_MAXVARSIZE, "%s_%s", distrib, codename);
        AddClassToHeap(classname);
        }

    if ((release  = lsb_release(path, "--release")) != NULL)
        {
        switch (sscanf(release, "%d.%d\n", &major, &minor))
            {
            case 2:
                snprintf(classname, CF_MAXVARSIZE, "%s_%u_%u", distrib, major, minor);
                AddClassToHeap(classname);
            case 1:
                snprintf(classname, CF_MAXVARSIZE, "%s_%u", distrib, major);
                AddClassToHeap(classname);
            }
        }

    free(path);
    return 0;
    }
else
    {
    free(path);
    return 2;
    }
}