File passcheck.c of Package ntop

/* 
   Copyright (c) 2002 SuSE AG Nuernberg, Germany.
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


   This program checks if a password is set for the default admin user
   of ntop.
*/ 

#include <gdbm.h>
#include <stdio.h>

size_t strlen(const char *s);

int main(int argc, char *argv[]) {
  datum key_data, return_data;
  GDBM_FILE dbf;

  dbf=gdbm_open( "/var/lib/ntop/ntop_pw.db" , 0, GDBM_WRCREAT, 00664, NULL);
  if (!dbf)
	  return 2;
  
  key_data.dptr = "1admin";
  key_data.dsize = strlen(key_data.dptr)+1;

  return_data = gdbm_fetch(dbf, key_data);
  
  if(return_data.dptr == NULL) {
    return 1;
  }
  return 0;
}