Esempio n. 1
0
static char *get_os_name(const OSVERSIONINFOEX osinfo)
{
    char *name;
    char tmp[10];
    int r = 0;

    /* we only compile on 2k or newer, which is version 5
     * Covers 2000, XP and 2003 */
    if (osinfo.dwMajorVersion != 5) {
        return "Unknown";
    }
    switch(osinfo.dwMinorVersion) {
    case 0: /* Windows 2000 */
        name = strdup(WINDOWS2000);
        if(name == NULL) {
            goto out;
        }
        if (osinfo.wProductType == VER_NT_WORKSTATION) {
            r = home_or_pro(osinfo, &name);
        } else if (osinfo.wSuiteMask & VER_SUITE_DATACENTER) {
            r = sg_concat_string(&name, " Datacenter Server");
        } else if (osinfo.wSuiteMask & VER_SUITE_ENTERPRISE) {
            r = sg_concat_string(&name, " Advanced Server");
        } else {
            r = sg_concat_string(&name, " Server");
        }
        break;
    case 1: /* Windows XP */
        name = strdup(WINDOWSXP);
        if(name == NULL) {
            goto out;
        }
        r = home_or_pro(osinfo, &name);
        break;
    case 2: /* Windows 2003 */
        name = strdup(WINDOWS2003);
        if(name == NULL) {
            goto out;
        }
        if (osinfo.wSuiteMask & VER_SUITE_DATACENTER) {
            r = sg_concat_string(&name, " Datacenter Edition");
        } else if (osinfo.wSuiteMask & VER_SUITE_ENTERPRISE) {
            r = sg_concat_string(&name, " Enterprise Edition");
        } else if (osinfo.wSuiteMask & VER_SUITE_BLADE) {
            r = sg_concat_string(&name, " Web Edition");
        } else {
            r = sg_concat_string(&name, " Standard Edition");
        }
        break;
    default:
        name = strdup("Windows 2000 based");
        break;
    }
    if(r != 0) {
        free (name);
        return NULL;
    }
    /* Add on service pack version */
    if (osinfo.wServicePackMajor != 0) {
        if(osinfo.wServicePackMinor == 0) {
            if(snprintf(tmp, sizeof(tmp), " SP%d", osinfo.wServicePackMajor) != -1) {
                r = sg_concat_string(&name, tmp);
            }
        } else {
            if(snprintf(tmp, sizeof(tmp), " SP%d.%d", osinfo.wServicePackMajor,
                        osinfo.wServicePackMinor) != -1) {
                r = sg_concat_string(&name, tmp);
            }
        }
        if(r) {
            free(name);
            return NULL;
        }
    }
    return name;

out:
    /* strdup failed */
    sg_set_error_with_errno(SG_ERROR_MALLOC, NULL);
    return NULL;
}
Esempio n. 2
0
static char *
get_os_name(const OSVERSIONINFOEX osinfo, SYSTEM_INFO sysinfo)
{
	char *name;
	char tmp[10];
	int r = 0;

	/* we only compile on 2k or newer, which is version 5
	 * Covers 2000, XP and 2003 */
	if (osinfo.dwMajorVersion != 5) {
		return "Unknown";
	}
	switch(osinfo.dwMinorVersion) {
		case 0: /* Windows 2000 */
			name = strdup(WINDOWS2000);
			if(name == NULL) {
				goto out;
			}
			if (osinfo.wProductType == VER_NT_WORKSTATION) {
				r = home_or_pro(osinfo, &name);
			} else if (osinfo.wSuiteMask & VER_SUITE_DATACENTER) {
				r = sg_concat_string(&name, " Datacenter Server");
			} else if (osinfo.wSuiteMask & VER_SUITE_ENTERPRISE) {
				r = sg_concat_string(&name, " Advanced Server");
			} else {
				r = sg_concat_string(&name, " Server");
			}
			break;
		case 1: /* Windows XP */
			name = strdup(WINDOWSXP);
			if(name == NULL) {
				goto out;
			}
			r = home_or_pro(osinfo, &name);
			break;
		case 2: /* Windows 2003 */
			/* XXX complete detection using http://msdn.microsoft.com/en-us/library/ms724833%28VS.85%29.aspx */
			if( (osinfo.wProductType == VER_NT_WORKSTATION) &&
			    (sysinfo.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) ) {
				name = strdup(WINDOWSXP);
				r = home_or_pro(osinfo, &name);
				r = sg_concat_string(&name, " x64 Edition");
			}
			else {
				name = strdup(WINDOWS2003);
			}

			if(name == NULL) {
				goto out;
			}
			if (osinfo.wSuiteMask & VER_SUITE_DATACENTER) {
				r = sg_concat_string(&name, " Datacenter Edition");
			} else if (osinfo.wSuiteMask & VER_SUITE_ENTERPRISE) {
				r = sg_concat_string(&name, " Enterprise Edition");
			} else if (osinfo.wSuiteMask & VER_SUITE_BLADE) {
				r = sg_concat_string(&name, " Web Edition");
			} else {
				r = sg_concat_string(&name, " Standard Edition");
			}
			break;
		default:
			name = strdup("Windows 2000 based");
			break;
	}
	if(r != 0) {
		free (name);
		return NULL;
	}
	/* Add on service pack version */
	if (osinfo.wServicePackMajor != 0) {
		if(osinfo.wServicePackMinor == 0) {
			if(snprintf(tmp, sizeof(tmp), " SP%d", osinfo.wServicePackMajor) != -1) {
				r = sg_concat_string(&name, tmp);
			}
		} else {
			if(snprintf(tmp, sizeof(tmp), " SP%d.%d", osinfo.wServicePackMajor,
					osinfo.wServicePackMinor) != -1) {
				r = sg_concat_string(&name, tmp);
			}
		}
		if(r) {
			free(name);
			return NULL;
		}
	}
	return name;

out:
	/* strdup failed */
	SET_ERROR_WITH_ERRNO("os", SG_ERROR_MALLOC, "get_os_name: strdup() failed");
	return NULL;
}