Back to index

php5  5.3.10
Defines | Functions
winutil.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define php_win_err()   php_win_err(GetLastError())
#define php_win32_init_rng_lock()   ;
#define php_win32_free_rng_lock()   ;

Functions

PHPAPI char * php_win_err (int error)
int php_win32_check_trailing_space (const char *path, const int path_len)
PHPAPI php_win32_get_random_bytes (unsigned char *buf, size_t size)

Define Documentation

#define php_win32_free_rng_lock ( )    ;

Definition at line 30 of file winutil.h.

#define php_win32_init_rng_lock ( )    ;

Definition at line 29 of file winutil.h.

#define php_win_err ( )    php_win_err(GetLastError())

Definition at line 21 of file winutil.h.


Function Documentation

int php_win32_check_trailing_space ( const char *  path,
const int  path_len 
)

Definition at line 37 of file winutil.c.

                                                                          {
       if (path_len < 1) {
              return 1;
       }
       if (path) {
              if (path[0] == ' ' || path[path_len - 1] == ' ') {
                     return 0;
              } else {
                     return 1;
              }
       } else {
              return 0;
       }
}

Here is the caller graph for this function:

PHPAPI php_win32_get_random_bytes ( unsigned char *  buf,
size_t  size 
)

Definition at line 78 of file winutil.c.

                                                                       {  /* {{{ */

       unsigned int has_contextg = 0;

       BOOL ret;
       size_t i = 0;

#ifdef ZTS
       tsrm_mutex_lock(php_lock_win32_cryptoctx);
#endif

       if (has_crypto_ctx == 0) {
              /* CRYPT_VERIFYCONTEXT > only hashing&co-like use, no need to acces prv keys */
              if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_MACHINE_KEYSET|CRYPT_VERIFYCONTEXT )) {
                     /* Could mean that the key container does not exist, let try 
                        again by asking for a new one. If it fails here, it surely means that the user running 
               this process does not have the permission(s) to use this container.
             */
                     if (GetLastError() == NTE_BAD_KEYSET) {
                            if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET | CRYPT_MACHINE_KEYSET | CRYPT_VERIFYCONTEXT )) {
                                   has_crypto_ctx = 1;
                            } else {
                                   has_crypto_ctx = 0;
                            }
                     }
              } else {
                     has_crypto_ctx = 1;
              }
       }

#ifdef ZTS
       tsrm_mutex_unlock(php_lock_win32_cryptoctx);
#endif

       if (has_crypto_ctx == 0) {
              return FAILURE;
       }

       ret = CryptGenRandom(hCryptProv, size, buf);

       if (ret) {
              return SUCCESS;
       } else {
              return FAILURE;
       }
}

Here is the caller graph for this function:

PHPAPI char* php_win_err ( int  error)

Definition at line 25 of file winutil.c.

{
       char *buf = NULL;

       FormatMessage(
              FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |  FORMAT_MESSAGE_IGNORE_INSERTS,
              NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, 0, NULL
       );

       return (buf ? (char *) buf : "");
}