| 1120 | |
| 1121 | |
| 1122 | Status InitAuth(const string& appname) { |
| 1123 | if (APP_NAME.empty()) { |
| 1124 | APP_NAME = appname; |
| 1125 | } else if (APP_NAME != appname) { |
| 1126 | return Status(TErrorCode::SASL_APP_NAME_MISMATCH, APP_NAME, appname); |
| 1127 | } |
| 1128 | |
| 1129 | // Setup basic callbacks for Sasl. We initialize SASL always since KRPC expects it to |
| 1130 | // be initialized. |
| 1131 | // Good idea to have logging everywhere |
| 1132 | GENERAL_CALLBACKS[0].id = SASL_CB_LOG; |
| 1133 | GENERAL_CALLBACKS[0].proc = (int (*)())&SaslLogCallback; |
| 1134 | GENERAL_CALLBACKS[0].context = ((void *)"General"); |
| 1135 | |
| 1136 | int arr_offset = 0; |
| 1137 | if (!FLAGS_sasl_path.empty()) { |
| 1138 | // Need this here so we can find available mechanisms |
| 1139 | GENERAL_CALLBACKS[1].id = SASL_CB_GETPATH; |
| 1140 | GENERAL_CALLBACKS[1].proc = (int (*)())&SaslGetPath; |
| 1141 | GENERAL_CALLBACKS[1].context = NULL; |
| 1142 | arr_offset = 1; |
| 1143 | } |
| 1144 | |
| 1145 | // Allows us to view and set some options |
| 1146 | GENERAL_CALLBACKS[1 + arr_offset].id = SASL_CB_GETOPT; |
| 1147 | GENERAL_CALLBACKS[1 + arr_offset].proc = (int (*)())&SaslGetOption; |
| 1148 | GENERAL_CALLBACKS[1 + arr_offset].context = NULL; |
| 1149 | |
| 1150 | // For curiosity, let's see what files are being touched. |
| 1151 | GENERAL_CALLBACKS[2 + arr_offset].id = SASL_CB_VERIFYFILE; |
| 1152 | GENERAL_CALLBACKS[2 + arr_offset].proc = (int (*)())&SaslVerifyFile; |
| 1153 | GENERAL_CALLBACKS[2 + arr_offset].context = NULL; |
| 1154 | |
| 1155 | GENERAL_CALLBACKS[3 + arr_offset].id = SASL_CB_LIST_END; |
| 1156 | |
| 1157 | // Other than the general callbacks, we only setup other SASL things as required. |
| 1158 | if (FLAGS_enable_ldap_auth || IsKerberosEnabled()) { |
| 1159 | if (IsKerberosEnabled()) { |
| 1160 | // Callbacks for when we're a Kerberos Sasl internal connection. Just do logging. |
| 1161 | KERB_INT_CALLBACKS.resize(3); |
| 1162 | |
| 1163 | KERB_INT_CALLBACKS[0].id = SASL_CB_LOG; |
| 1164 | KERB_INT_CALLBACKS[0].proc = (int (*)())&SaslLogCallback; |
| 1165 | KERB_INT_CALLBACKS[0].context = ((void *)"Kerberos (internal)"); |
| 1166 | |
| 1167 | KERB_INT_CALLBACKS[1].id = SASL_CB_PROXY_POLICY; |
| 1168 | KERB_INT_CALLBACKS[1].proc = (int (*)())&SaslAuthorizeInternal; |
| 1169 | KERB_INT_CALLBACKS[1].context = NULL; |
| 1170 | |
| 1171 | KERB_INT_CALLBACKS[2].id = SASL_CB_LIST_END; |
| 1172 | |
| 1173 | // Our externally facing Sasl callbacks for Kerberos communication |
| 1174 | KERB_EXT_CALLBACKS.resize(3); |
| 1175 | |
| 1176 | KERB_EXT_CALLBACKS[0].id = SASL_CB_LOG; |
| 1177 | KERB_EXT_CALLBACKS[0].proc = (int (*)())&SaslLogCallback; |
| 1178 | KERB_EXT_CALLBACKS[0].context = ((void *)"Kerberos (external)"); |
| 1179 | |