/[monit]/monit/util.c
ViewVC logotype

Diff of /monit/util.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.100 by hauk, Wed Oct 8 02:14:23 2003 UTC revision 1.101 by chopp, Wed Oct 8 21:07:33 2003 UTC
# Line 82  Line 82 
82  #include <sys/stat.h>  #include <sys/stat.h>
83  #endif  #endif
84    
85    #ifdef HAVE_CRYPT_H
86    #include <crypt.h>
87    #endif
88    
89  #include "monitor.h"  #include "monitor.h"
90  #include "engine.h"  #include "engine.h"
91  #include "md5.h"  #include "md5.h"
# Line 1100  char *url_encode(char *uri) { Line 1104  char *url_encode(char *uri) {
1104   */   */
1105  char *get_basic_authentication_header() {  char *get_basic_authentication_header() {
1106    
1107    if(Run.credentials!=NULL) {    Auth_T c=Run.credentials;
1108    
1109      if (c==NULL) {
1110    
1111        return xstrdup("\r\n");
1112    
1113      }
1114      
1115      /* We find the first cleartext credential for authorization */
1116      
1117      while (c!= NULL) {
1118    
1119        if (c->digesttype == DIGEST_CLEARTEXT) {
1120    
1121          break;
1122          
1123        }
1124        
1125        c=c->next;
1126        
1127      }
1128      
1129      if(c!=NULL) {
1130    
1131      char *auth, *b64;      char *auth, *b64;
1132      char  buf[STRLEN];      char  buf[STRLEN];
1133    
     /* We use the first credential for authorization */  
1134      snprintf(buf, STRLEN, "%s:%s",      snprintf(buf, STRLEN, "%s:%s",
1135               Run.credentials->uname,               c->uname,
1136               Run.credentials->passwd);               c->passwd);
1137    
1138      if(! (b64= encode_base64(strlen(buf), (unsigned char *)buf)) ) {      if(! (b64= encode_base64(strlen(buf), (unsigned char *)buf)) ) {
1139        log("Failed to base64 encode authentication header\n");        log("Failed to base64 encode authentication header\n");
1140        return xstrdup("\r\n");        return NULL;
1141      }      }
1142    
1143      auth= xcalloc(sizeof(char), STRLEN+1);      auth= xcalloc(sizeof(char), STRLEN+1);
# Line 1123  char *get_basic_authentication_header() Line 1148  char *get_basic_authentication_header()
1148    
1149    }    }
1150    
1151    return xstrdup("\r\n");    log("Cleattext credentials needed for basic authorization!\n");
1152      return NULL;
1153    
1154  }  }
1155    
# Line 1209  void fd_close() { Line 1235  void fd_close() {
1235   * Check if monit does have credentials for this user.  If successful   * Check if monit does have credentials for this user.  If successful
1236   * a pointer to the password is returned.   * a pointer to the password is returned.
1237   */   */
1238  char * get_user_credentials(char *uname) {  Auth_T get_user_credentials(char *uname) {
1239    
1240    Auth_T c= Run.credentials;    Auth_T c= Run.credentials;
1241        
# Line 1217  char * get_user_credentials(char *uname) Line 1243  char * get_user_credentials(char *uname)
1243    
1244      if ( strcmp(c->uname, uname) == 0 ) {      if ( strcmp(c->uname, uname) == 0 ) {
1245    
1246        return c->passwd;        return c;
1247                
1248      }      }
1249            
# Line 1229  char * get_user_credentials(char *uname) Line 1255  char * get_user_credentials(char *uname)
1255  }  }
1256    
1257    
1258    int compare_user_credentials(char *uname, char *outside) {
1259    
1260      Auth_T c= get_user_credentials(uname);
1261      char outside_crypt[STRLEN];
1262      
1263      if ( c==NULL ) {
1264    
1265        return FALSE;
1266        
1267      }
1268      switch (c->digesttype) {
1269      case DIGEST_CLEARTEXT:
1270      {
1271        strcpy(outside_crypt, outside);
1272    
1273        break;
1274      }  
1275      case DIGEST_MD5:
1276      {
1277        char id[STRLEN];
1278        char salt[STRLEN];
1279        char * temp;
1280    
1281        /* A password looks like this,
1282         *   $id$salt$digest
1283         * the '$' around the id are still part of the id.
1284         */
1285    
1286        strcpy(id, c->passwd);
1287        temp= strchr(id+1, '$')+1;
1288        *temp= '\0';
1289    
1290        strcpy(salt, c->passwd+strlen(id));
1291        temp= strchr(salt, '$');
1292        *temp= '\0';
1293    
1294        if (md5_crypt(outside, id, salt, outside_crypt, STRLEN) == NULL) {
1295    
1296          log("Cannot generate MD5 digest error.\n");
1297          return FALSE;
1298          
1299        }
1300        
1301        break;
1302      }
1303      case DIGEST_CRYPT:
1304      {
1305        char salt[3];
1306        char * temp;
1307        snprintf(salt, 3, "%c%c", c->passwd[0], c->passwd[1]);
1308        temp= crypt(outside, salt);
1309        strcpy(outside_crypt, temp);
1310        
1311        break;
1312      }
1313      
1314      default:
1315          log("Unknown password digestion method.\n");
1316          return FALSE;
1317      }
1318    
1319      if (strcmp(outside_crypt,c->passwd)==0) {
1320        return TRUE;
1321      }
1322    
1323      return FALSE;
1324    }
1325    
1326    
1327  /* ----------------------------------------------------------------- Private */  /* ----------------------------------------------------------------- Private */
1328    
1329    

Legend:
Removed from v.1.100  
changed lines
  Added in v.1.101

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26