Skip to content

[Console] Add additional ways to detect OS400 platform #16095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

johnkary
Copy link
Contributor

@johnkary johnkary commented Oct 3, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16053
License MIT
Doc PR None

This PR adds support for detecting the OS400 platform when the PHP function php_uname() is disabled. OS400 platform detection was added in #15058 to fix character encoding issues present on OS400. See that PR for more info.

This PR fixes regression introduced in #16053, which did not work on the IBM OS400 server I have access to. The constant PHP_OS being checked outputs "AIX" on my IBM OS400 server. I can't say for sure if it works on other IBM platforms... but I preserved this check just in case.

User @eloigranado commented here asking if we could switch to using PHP_OS constant instead of php_uname() because he claims some admins might "[hide] the exact kernel build from any attacker who discovers a remote PHP code execution vulnerability". I personally don't think we should accommodate this use case, but I was able to find alternate approaches.

Why use case insensitive string matching stristr() instead of in_array()?

Here are the various outputs on my OS400 server:

echo PHP_OS; // "AIX"
echo getenv('OSTYPE'); // "os400"
echo php_uname('s'); // "OS400"

So we have various case issues here, and possible blank values on platforms where OSTYPE var doesn't exist or php_uname() is disabled. Concatenating these optional values together delimited by ; then case-insensitive searching the string for "OS400" seemed like a fair compromise. I would've probably done in_array() if case wasn't an issue.

This reverts commit 40e0dc8.

This commit led to a regression on the OS400 platform, where the
constant PHP_OS returns "AIX" not "OS400".
$checks = array(
function_exists('php_uname') ? php_uname('s') : '',
getenv('OSTYPE'),
defined('PHP_OS') ? PHP_OS : '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check can be omitted IMO, we can be sure that the PHP_OS constant exists.

@johnkary
Copy link
Contributor Author

johnkary commented Oct 3, 2015

@dosten Thank you for the quick review. I have made the changes you suggested.

@xabbuh
Copy link
Member

xabbuh commented Oct 3, 2015

@johnkary Thank you for the review. On http://www.volubis.fr/php/ibmdemo/showsource.php?filename=checkauth.inc I found this check:

// If we report the OS as AIX or OS400, assume we're running under PASE
$isPase = (PHP_OS == "AIX" || PHP_OS == "OS400");

Should we do it similarly here?

@johnkary
Copy link
Contributor Author

johnkary commented Oct 3, 2015

@xabbuh Thank you for the reference link.

According to php_uname() docs PHP_OS constant will contain the operating system PHP was _built_ on. Is it possible the system that built PHP is not necessarily the system where it is running?

I'm not an IBM expert, nor do I admin IBM servers. I can only offer evidence from the 1 server I have access to. PHP_OS constant returns "AIX" on that server. Maybe AIX is the deciding factor when we should redirect output, instead of OS400? I'm willing to rework the PR if others think that is a better approach.

@fabpot fabpot added the Console label Oct 5, 2015
@fabpot
Copy link
Member

fabpot commented Oct 7, 2015

Thank you @johnkary.

fabpot added a commit that referenced this pull request Oct 7, 2015
…hnkary)

This PR was squashed before being merged into the 2.3 branch (closes #16095).

Discussion
----------

[Console] Add additional ways to detect OS400 platform

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16053
| License       | MIT
| Doc PR        | None

This PR adds support for detecting the OS400 platform when the PHP function `php_uname()` is disabled. OS400 platform detection was added in #15058 to fix character encoding issues present on OS400. See that PR for more info.

This PR fixes regression introduced in #16053, which did not work on the IBM OS400 server I have access to. The constant `PHP_OS` being checked outputs "AIX" on my IBM OS400 server. I can't say for sure if it works on other IBM platforms... but I preserved this check just in case.

User @eloigranado [commented here](#15058 (comment)) asking if we could switch to using `PHP_OS` constant instead of `php_uname()` because he claims some admins might "[hide] the exact kernel build from any attacker who discovers a remote PHP code execution vulnerability". I personally don't think we should accommodate this use case, but I was able to find alternate approaches.

### Why use case insensitive string matching stristr() instead of in_array()?

Here are the various outputs on my OS400 server:

    echo PHP_OS; // "AIX"
    echo getenv('OSTYPE'); // "os400"
    echo php_uname('s'); // "OS400"

So we have various case issues here, and possible blank values on platforms where OSTYPE var doesn't exist or php_uname() is disabled. Concatenating these optional values together delimited by ; then case-insensitive searching the string for "OS400" seemed like a fair compromise. I would've probably done `in_array()` if case wasn't an issue.

Commits
-------

96a4071 [Console] Add additional ways to detect OS400 platform
@fabpot fabpot closed this Oct 7, 2015
@eloigranado
Copy link

Thank you for your efforts with this @johnkary and @xabbuh, they are highly appreciated. You have solved the issue in a really more comprehensive way than I could have.

This was referenced Oct 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants