Projet

Général

Profil

Paste
Télécharger (4,83 ko) Statistiques
| Branche: | Révision:

root / htmltest / modules / openid / openid.install @ 85ad3d82

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the openid module.
6
 */
7

    
8
/**
9
 * Implements hook_schema().
10
 */
11
function openid_schema() {
12
  $schema['openid_association'] = array(
13
    'description' => 'Stores temporary shared key association information for OpenID authentication.',
14
    'fields' => array(
15
      'idp_endpoint_uri' => array(
16
        'type' => 'varchar',
17
        'length' => 255,
18
        'description' => 'URI of the OpenID Provider endpoint.',
19
      ),
20
      'assoc_handle' => array(
21
        'type' => 'varchar',
22
        'length' => 255,
23
        'not null' => TRUE,
24
        'description' => 'Primary Key: Used to refer to this association in subsequent messages.',
25
      ),
26
      'assoc_type' => array(
27
        'type' => 'varchar',
28
        'length' => 32,
29
        'description' => 'The signature algorithm used: one of HMAC-SHA1 or HMAC-SHA256.',
30
      ),
31
      'session_type' => array(
32
        'type' => 'varchar',
33
        'length' => 32,
34
        'description' => 'Valid association session types: "no-encryption", "DH-SHA1", and "DH-SHA256".',
35
      ),
36
      'mac_key' => array(
37
        'type' => 'varchar',
38
        'length' => 255,
39
        'description' => 'The MAC key (shared secret) for this association.',
40
      ),
41
      'created' => array(
42
        'type' => 'int',
43
        'not null' => TRUE,
44
        'default' => 0,
45
        'description' => 'UNIX timestamp for when the association was created.',
46
      ),
47
      'expires_in' => array(
48
        'type' => 'int',
49
        'not null' => TRUE,
50
        'default' => 0,
51
        'description' => 'The lifetime, in seconds, of this association.',
52
      ),
53
    ),
54
    'primary key' => array('assoc_handle'),
55
  );
56

    
57
  $schema['openid_nonce'] = array(
58
    'description' => 'Stores received openid.response_nonce per OpenID endpoint URL to prevent replay attacks.',
59
    'fields' => array(
60
      'idp_endpoint_uri' => array(
61
        'type' => 'varchar',
62
        'length' => 255,
63
        'description' => 'URI of the OpenID Provider endpoint.',
64
      ),
65
      'nonce' => array(
66
        'type' => 'varchar',
67
        'length' => 255,
68
        'description' => 'The value of openid.response_nonce.',
69
      ),
70
      'expires' => array(
71
        'type' => 'int',
72
        'not null' => TRUE,
73
        'default' => 0,
74
        'description' => 'A Unix timestamp indicating when the entry should expire.',
75
      ),
76
    ),
77
    'indexes' => array(
78
      'nonce' => array('nonce'),
79
      'expires' => array('expires'),
80
    ),
81
  );
82

    
83
  return $schema;
84
}
85

    
86
/**
87
 * Implements hook_requirements().
88
 */
89
function openid_requirements($phase) {
90
  $requirements = array();
91

    
92
  if ($phase == 'runtime') {
93
    // Check for the PHP BC Math library.
94
    if (!function_exists('bcadd') && !function_exists('gmp_add')) {
95
      $requirements['openid_math'] = array(
96
        'value' => t('Not installed'),
97
        'severity' => REQUIREMENT_ERROR,
98
        'description' => t('OpenID suggests the use of either the <a href="@gmp">GMP Math</a> (recommended for performance) or <a href="@bc">BC Math</a> libraries to enable OpenID associations.', array('@gmp' => 'http://php.net/manual/en/book.gmp.php', '@bc' => 'http://www.php.net/manual/en/book.bc.php')),
99
      );
100
    }
101
    elseif (!function_exists('gmp_add')) {
102
      $requirements['openid_math'] = array(
103
        'value' => t('Not optimized'),
104
        'severity' => REQUIREMENT_WARNING,
105
        'description' => t('OpenID suggests the use of the GMP Math library for PHP for optimal performance. Check the <a href="@url">GMP Math Library documentation</a> for installation instructions.', array('@url' => 'http://www.php.net/manual/en/book.gmp.php')),
106
      );
107
    }
108
    else {
109
      $requirements['openid_math'] = array(
110
        'value' => t('Installed'),
111
        'severity' => REQUIREMENT_OK,
112
      );
113
    }
114
    $requirements['openid_math']['title'] = t('OpenID Math library');
115
  }
116

    
117
  return $requirements;
118
}
119

    
120
/**
121
 * @addtogroup updates-6.x-to-7.x
122
 * @{
123
 */
124

    
125
/**
126
 * Add a table to store nonces.
127
 */
128
function openid_update_6000() {
129
  $schema['openid_nonce'] = array(
130
    'description' => 'Stores received openid.response_nonce per OpenID endpoint URL to prevent replay attacks.',
131
    'fields' => array(
132
      'idp_endpoint_uri' => array(
133
        'type' => 'varchar',
134
        'length' => 255,
135
        'description' => 'URI of the OpenID Provider endpoint.',
136
      ),
137
      'nonce' => array(
138
        'type' => 'varchar',
139
        'length' => 255,
140
        'description' => 'The value of openid.response_nonce'
141
        ),
142
      'expires' => array(
143
        'type' => 'int',
144
        'not null' => TRUE,
145
        'default' => 0,
146
        'description' => 'A Unix timestamp indicating when the entry should expire.',
147
        ),
148
      ),
149
    'indexes' => array(
150
      'nonce' => array('nonce'),
151
      'expires' => array('expires'),
152
    ),
153
  );
154

    
155
  db_create_table('openid_nonce', $schema['openid_nonce']);
156
}
157

    
158
/**
159
 * @} End of "addtogroup updates-6.x-to-7.x".
160
 */