Commit b8ca5bc6 authored by claes's avatar claes

Login window in runtime added

parent 80bbd186
/*
* Proview $Id: co_login_gtk.cpp,v 1.1 2008-06-24 06:51:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include "co_login_msg.h"
#include "co_login_gtk.h"
#include "co_api.h"
#include "co_dcli.h"
//
// Callback from the pushbutton.
//
void CoLoginGtk::activate_ok( GtkWidget *w, gpointer data)
{
CoLogin *loginctx = (CoLogin *)data;
loginctx->activate_ok();
}
//
// Callback from the pushbutton.
//
void CoLoginGtk::activate_cancel( GtkWidget *w, gpointer data)
{
CoLogin *loginctx = (CoLogin *)data;
loginctx->activate_cancel();
}
//
// Callback when value changed.
//
void CoLoginGtk::valchanged_passwordvalue( GtkWidget *w, gpointer data)
{
CoLogin *loginctx = (CoLogin *)data;
gtk_widget_activate( ((CoLoginGtk *)loginctx)->widgets.okbutton);
}
//
// Callback when value changed.
//
void CoLoginGtk::valchanged_usernamevalue( GtkWidget *w, gpointer data)
{
CoLogin *loginctx = (CoLogin *)data;
gtk_widget_grab_focus( ((CoLoginGtk *)loginctx)->widgets.passwordvalue);
}
static gboolean login_action_inputfocus( GtkWidget *w, GdkEvent *event, gpointer data)
{
return FALSE;
}
static gint login_delete_event( GtkWidget *w, GdkEvent *event, gpointer data)
{
CoLogin *loginctx = (CoLogin *)data;
loginctx->activate_cancel();
return TRUE;
}
//
// Constructor
//
CoLoginGtk::CoLoginGtk( void *wl_parent_ctx,
GtkWidget *wl_parent_wid,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)( void *),
void (* wl_bc_cancel)( void *),
pwr_tStatus *status) :
CoLogin(wl_parent_ctx,wl_name,wl_groupname,wl_bc_success,wl_bc_cancel,status),
parent_wid(wl_parent_wid)
{
const int window_width = 500;
const int window_height = 200;
// Create an input dialog
widgets.toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW,
"default-height", window_height,
"default-width", window_width,
"title", "Proview Login",
NULL);
g_signal_connect( widgets.toplevel, "delete_event", G_CALLBACK(login_delete_event), this);
g_signal_connect( widgets.toplevel, "focus-in-event", G_CALLBACK(login_action_inputfocus), this);
widgets.usernamevalue = gtk_entry_new();
gtk_widget_set_size_request( widgets.usernamevalue, -1, 20);
g_signal_connect( widgets.usernamevalue, "activate",
G_CALLBACK(valchanged_usernamevalue), this);
GtkWidget *usernamelabel = gtk_label_new("Username");
gtk_widget_set_size_request( usernamelabel, -1, 20);
widgets.passwordvalue = gtk_entry_new();
gtk_widget_set_size_request( widgets.passwordvalue, -1, 20);
g_signal_connect( widgets.passwordvalue, "activate",
G_CALLBACK(valchanged_passwordvalue), this);
GtkWidget *passwordlabel = gtk_label_new("Password");
gtk_widget_set_size_request( passwordlabel, -1, 20);
gtk_entry_set_visibility( GTK_ENTRY(widgets.passwordvalue), FALSE);
pwr_tFileName fname;
dcli_translate_filename( fname, "$pwr_exe/proview_icon2.png");
GtkWidget *india_image = gtk_image_new_from_file( fname);
widgets.okbutton = gtk_button_new_with_label( "Ok");
gtk_widget_set_size_request( widgets.okbutton, 70, 25);
g_signal_connect( widgets.okbutton, "clicked",
G_CALLBACK(activate_ok), this);
GtkWidget *india_cancel = gtk_button_new_with_label( "Cancel");
gtk_widget_set_size_request( india_cancel, 70, 25);
g_signal_connect( india_cancel, "clicked",
G_CALLBACK(activate_cancel), this);
widgets.label = gtk_label_new("");
GtkWidget *vbox1 = gtk_vbox_new( FALSE, 0);
gtk_box_pack_start( GTK_BOX(vbox1), usernamelabel, FALSE, FALSE, 15);
gtk_box_pack_start( GTK_BOX(vbox1), passwordlabel, FALSE, FALSE, 15);
GtkWidget *vbox2 = gtk_vbox_new( FALSE, 0);
gtk_box_pack_start( GTK_BOX(vbox2), widgets.usernamevalue, FALSE, FALSE, 15);
gtk_box_pack_start( GTK_BOX(vbox2), widgets.passwordvalue, FALSE, FALSE, 15);
GtkWidget *hbox = gtk_hbox_new( FALSE, 0);
gtk_box_pack_start( GTK_BOX(hbox), india_image, FALSE, FALSE, 25);
gtk_box_pack_start( GTK_BOX(hbox), vbox1, FALSE, FALSE, 15);
gtk_box_pack_end( GTK_BOX(hbox), vbox2, TRUE, TRUE, 15);
GtkWidget *india_hboxbuttons = gtk_hbox_new( TRUE, 40);
gtk_box_pack_start( GTK_BOX(india_hboxbuttons), widgets.okbutton, FALSE, FALSE, 0);
gtk_box_pack_end( GTK_BOX(india_hboxbuttons), india_cancel, FALSE, FALSE, 0);
GtkWidget *india_vbox = gtk_vbox_new( FALSE, 0);
gtk_box_pack_start( GTK_BOX(india_vbox), hbox, TRUE, TRUE, 30);
gtk_box_pack_start( GTK_BOX(india_vbox), widgets.label, FALSE, FALSE, 5);
gtk_box_pack_start( GTK_BOX(india_vbox), gtk_hseparator_new(), FALSE, FALSE, 0);
gtk_box_pack_end( GTK_BOX(india_vbox), india_hboxbuttons, FALSE, FALSE, 15);
gtk_container_add( GTK_CONTAINER(widgets.toplevel), india_vbox);
gtk_widget_show_all( widgets.toplevel);
gtk_widget_grab_focus( widgets.usernamevalue);
*status = 1;
}
//
// Destructor
//
CoLoginGtk::~CoLoginGtk()
{
/* Destroy the widget */
gtk_widget_destroy( widgets.toplevel);
}
//
// Get values in username and password.
//
pwr_tStatus CoLoginGtk::get_values()
{
char passwd[40];
char username[40];
char *value;
pwr_tStatus sts;
/* Get UserName */
value = gtk_editable_get_chars( GTK_EDITABLE(widgets.usernamevalue), 0, -1);
strcpy(username, value);
g_free( value);
/* Get Password */
value = gtk_editable_get_chars( GTK_EDITABLE(widgets.passwordvalue), 0, -1);
strcpy(passwd, value);
sts = user_check( groupname, username, passwd);
if ( EVEN(sts))
return sts;
return LOGIN__SUCCESS;
}
//
// Displays a message in the login window.
//
void CoLoginGtk::message( char *new_label)
{
gtk_label_set_text( GTK_LABEL(widgets.label), new_label);
}
/*
* Proview $Id: co_login_gtk.h,v 1.1 2008-06-24 06:51:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef co_login_gtk_h
#define co_login_gtk_h
#ifndef co_login_h
#include "co_login.h"
#endif
struct login_widgets
{
GtkWidget *toplevel;
GtkWidget *login_window;
GtkWidget *label;
GtkWidget *okbutton;
GtkWidget *usernamevalue;
GtkWidget *passwordvalue;
};
class CoLoginGtk : public CoLogin {
public:
GtkWidget *parent_wid;
struct login_widgets widgets;
CoLoginGtk( void *wl_parent_ctx,
GtkWidget *wl_parent_wid,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)( void *),
void (* wl_bc_cancel)( void *),
pwr_tStatus *sts);
~CoLoginGtk();
pwr_tStatus get_values();
void message( char *new_label);
static void activate_ok( GtkWidget *w, gpointer data);
static void activate_cancel( GtkWidget *w, gpointer data);
static void valchanged_passwordvalue( GtkWidget *w, gpointer data);
static void valchanged_usernamevalue( GtkWidget *w, gpointer data);
};
#endif
/*
* Proview $Id: co_login_motif.cpp,v 1.1 2008-06-24 06:51:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Xm/Xm.h>
#include <Xm/Text.h>
#include <Mrm/MrmPublic.h>
#include <X11/Intrinsic.h>
#include "wb_login_msg.h"
#include "co_login_motif.h"
#include "co_api.h"
#include "co_dcli.h"
#define BEEP putchar( '\7' );
//
// Callback from the pushbutton.
//
void CoLoginMotif::activate_ok( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data)
{
loginctx->activate_ok();
}
//
// Callback from the pushbutton.
//
void CoLoginMotif::activate_cancel( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data)
{
loginctx->activate_cancel();
}
void CoLoginMotif::create_label( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data)
{
((CoLoginMotif *)loginctx)->widgets.label = w;
}
void CoLoginMotif::create_adb( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data)
{
((CoLoginMotif *)loginctx)->widgets.adb = w;
}
void CoLoginMotif::create_usernamevalue( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data)
{
((CoLoginMotif *)loginctx)->widgets.usernamevalue = w;
}
void CoLoginMotif::create_passwordvalue( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data)
{
((CoLoginMotif *)loginctx)->widgets.passwordvalue = w;
}
//
// Callback when value changed.
//
void CoLoginMotif::valchanged_passwordvalue( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data)
{
char *value;
int sts;
char *s;
if ( ((CoLoginMotif *)loginctx)->widgets.passwordvalue == 0)
return;
value = XmTextGetString( ((CoLoginMotif *)loginctx)->widgets.passwordvalue);
if ( *value == 0)
return;
s = strrchr( value, 10);
if (s == 0) {
strcat(loginctx->password, value);
XtFree( value);
XmTextSetString( ((CoLoginMotif *)loginctx)->widgets.passwordvalue, "");
return;
}
loginctx->message( "");
sts = loginctx->get_values();
if ( ODD(sts)) {
if (loginctx->bc_success != NULL)
(loginctx->bc_success) ( loginctx->parent_ctx);
XtFree( value);
delete loginctx;
return;
}
else {
loginctx->message( "User not authorized");
BEEP;
printf( "User not authorized\n");
XmTextSetString( ((CoLoginMotif *)loginctx)->widgets.passwordvalue, "");
strcpy(loginctx->password, "");
XtFree( value);
}
}
//
// Callback when value changed.
//
void CoLoginMotif::valchanged_usernamevalue( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data)
{
char *value;
char *s;
if ( ((CoLoginMotif *)loginctx)->widgets.usernamevalue == 0)
return;
value = XmTextGetString( ((CoLoginMotif *)loginctx)->widgets.usernamevalue);
if ( *value == 0)
return;
s = strrchr( value, 10);
if (s == 0)
{
XtFree( value);
return;
}
loginctx->message( "");
strcpy( s, s + 1);
XmTextSetString( ((CoLoginMotif *)loginctx)->widgets.usernamevalue, value);
XtFree( value);
/* Focus password */
XtSetKeyboardFocus( ((CoLoginMotif *)loginctx)->widgets.toplevel,
((CoLoginMotif *)loginctx)->widgets.passwordvalue);
}
//
// Constructor
//
CoLoginMotif::CoLoginMotif( void *wl_parent_ctx,
Widget wl_parent_wid,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)( void *),
void (* wl_bc_cancel)( void *),
pwr_tStatus *status) :
CoLogin(wl_parent_ctx,wl_name,wl_groupname,wl_bc_success,wl_bc_cancel,status),
parent_wid(wl_parent_wid)
{
Arg args[20];
int sts;
int i;
/* DRM database hierarchy related variables */
MrmHierarchy s_DRMh;
MrmType dclass;
char uid_filename[200] = {"pwr_exe:wb_login.uid"};
char *uid_filename_p = uid_filename;
static MrmRegisterArg reglist[] = {
/* First the context variable */
{ "login_ctx", 0 },
/* Callbacks for the controlled login widget */
{"login_create_adb",(caddr_t)create_adb},
{"login_create_label",(caddr_t)create_label},
{"login_create_usernamevalue",(caddr_t)create_usernamevalue},
{"login_create_passwordvalue",(caddr_t)create_passwordvalue},
{"login_valchanged_usernamevalue",(caddr_t)valchanged_usernamevalue},
{"login_valchanged_passwordvalue",(caddr_t)valchanged_passwordvalue},
{"login_activate_ok",(caddr_t)activate_ok},
{"login_activate_cancel",(caddr_t)activate_cancel},
};
static int reglist_num = (sizeof reglist / sizeof reglist[0]);
sts = dcli_translate_filename( uid_filename, uid_filename);
if ( EVEN(sts))
{
printf( "** pwr_exe is not defined\n");
exit(0);
}
/*
* Now start the module creation
*/
/* Save the context structure in the widget */
XtSetArg (args[0], XmNuserData, (unsigned int) this);
/*
* Create a new widget
* Open the UID files (the output of the UIL compiler) in the hierarchy
* Register the items DRM needs to bind for us.
* Create a new widget
* Close the hierarchy
* Compile the additional button translations and augment and add actions
*/
sts = MrmOpenHierarchy( 1, &uid_filename_p, NULL, &s_DRMh);
if (sts != MrmSUCCESS) printf("can't open hierarchy\n");
reglist[0].value = (caddr_t) this;
MrmRegisterNames(reglist, reglist_num);
i=0;
XtSetArg(args[i],XmNiconName,name); i++;
/* Save the id of the top in the context */
widgets.toplevel = XtCreatePopupShell (
"login", topLevelShellWidgetClass, parent_wid, args, i);
/* the positioning of a top level can only be define after the creation
* of the widget . So i do it now:
* use the parameters received x and y
*/
i=0;
XtSetArg(args[i],XmNx,100);i++;
XtSetArg(args[i],XmNy,100);i++;
XtSetArg(args[i],XtNallowShellResize,TRUE), i++;
XtSetValues( widgets.toplevel ,args,i);
/* now that we have a top level we can get the main window */
sts = MrmFetchWidgetOverride(s_DRMh, "login_window",
widgets.toplevel, name, args, 1,
&widgets.login_window, &dclass);
if (sts != MrmSUCCESS) printf("can't fetch utedit widget\n");
XtManageChild(widgets.login_window);
/* SG 09.02.91 a top level should always be realized ! */
XtPopup( widgets.toplevel, XtGrabNone );
MrmCloseHierarchy(s_DRMh);
*status = 1;
}
//
// Destructor
//
CoLoginMotif::~CoLoginMotif()
{
/* Destroy the widget */
XtDestroyWidget( widgets.toplevel) ;
}
//
// Get values in username and password.
//
pwr_tStatus CoLoginMotif::get_values()
{
char passwd[40];
char username[40];
char *value;
pwr_tStatus sts;
/* Get UserName */
value = XmTextGetString( widgets.usernamevalue);
strcpy(username, value);
XtFree( value);
/* Get Password */
strcpy(passwd, password);
sts = user_check( groupname, username, passwd);
if ( EVEN(sts))
return sts;
return LOGIN__SUCCESS;
}
//
// Displays a message in the login window.
//
void CoLoginMotif::message( char *new_label)
{
Arg args[2];
XtSetArg(args[0], XmNlabelString,
XmStringCreateLtoR( new_label , "ISO8859-1"));
XtSetValues( widgets.label, args, 1);
}
/*
* Proview $Id: co_login_motif.h,v 1.1 2008-06-24 06:51:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef co_login_motif_h
#define co_login_motif_h
#ifndef co_login_h
#include "co_login.h"
#endif
struct login_widgets
{
Widget toplevel;
Widget login_window;
Widget label;
Widget adb;
Widget usernamevalue;
Widget passwordvalue;
};
class CoLoginMotif : public CoLogin {
public:
Widget parent_wid;
struct login_widgets widgets;
CoLoginMotif( void *wl_parent_ctx,
Widget wl_parent_wid,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)( void *),
void (* wl_bc_cancel)( void *),
pwr_tStatus *sts);
~CoLoginMotif();
pwr_tStatus get_values();
void message( char *new_label);
static void activate_ok( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data);
static void activate_cancel( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data);
static void create_label( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data);
static void create_adb( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data);
static void create_usernamevalue( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data);
static void create_passwordvalue( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data);
static void valchanged_passwordvalue( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data);
static void valchanged_usernamevalue( Widget w, CoLogin *loginctx, XmAnyCallbackStruct *data);
};
#endif
/**
* Proview $Id: co_api_user.cpp,v 1.1 2008-06-24 06:51:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#if defined OS_VMS && defined __ALPHA
# pragma message disable (NOSIMPINT,EXTROUENCUNNOBJ)
#endif
#if defined OS_VMS && !defined __ALPHA
# pragma message disable (LONGEXTERN)
#endif
#include <stdio.h>
#include <stdlib.h>
#include "pwr.h"
#include "co_api_user.h"
#include "co_dcli.h"
#include "co_user.h"
//
// c-api to co_user
//
int user_CheckUser( char *systemgroup, char *user, char *password,
unsigned int *priv)
{
GeUser *gu;
int sts;
char filename[120];
gu = new GeUser();
sts = dcli_get_defaultfilename( user_cFilename, filename, "");
sts = gu->load( filename);
if ( ODD(sts))
sts = gu->get_user( systemgroup, user, password, priv);
delete gu;
return sts;
}
int user_CheckSystemGroup( char *systemgroup)
{
GeUser *gu;
int sts;
pwr_tMask attributes;
char filename[120];
pwr_tOix id;
pwr_tString80 desc;
gu = new GeUser();
sts = dcli_get_defaultfilename( user_cFilename, filename, "");
sts = gu->load( filename);
if ( ODD(sts))
sts = gu->get_system_data( systemgroup, &attributes, &id, desc);
delete gu;
return sts;
}
int user_GetUserPriv( char *systemgroup, char *user, unsigned int *priv)
{
GeUser *gu;
int sts;
char filename[120];
gu = new GeUser();
sts = dcli_get_defaultfilename( user_cFilename, filename, "");
sts = gu->load( filename);
if ( ODD(sts))
sts = gu->get_user_priv( systemgroup, user, priv);
delete gu;
return sts;
}
void user_PrivToString( unsigned int priv, char *str, int size)
{
GeUser::priv_to_string( priv, str, size);
}
void user_RtPrivToString( unsigned int priv, char *str, int size)
{
GeUser::rt_priv_to_string( priv, str, size);
}
void user_DevPrivToString( unsigned int priv, char *str, int size)
{
GeUser::dev_priv_to_string( priv, str, size);
}
char *user_PwCrypt( char *password)
{
return UserList::pwcrypt( password);
}
/**
* Proview $Id: co_api_user.h,v 1.1 2008-06-24 06:51:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef co_api_user_h
#define co_api_user_h
#if defined __cplusplus
extern "C" {
#endif
int user_CheckUser( char *systemgroup, char *user, char *password,
unsigned int *priv);
int user_CheckSystemGroup( char *systemgroup);
int user_GetUserPriv( char *systemgroup, char *user, unsigned int *priv);
void user_PrivToString( unsigned int priv, char *str, int size);
void user_RtPrivToString( unsigned int priv, char *str, int size);
void user_DevPrivToString( unsigned int priv, char *str, int size);
char *user_PwCrypt( char *password);
#if defined __cplusplus
}
#endif
#endif
/*
* Proview $Id: co_login.cpp,v 1.1 2008-06-24 06:51:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wb_login_msg.h"
#include "co_login.h"
#include "co_user.h"
#include "co_api.h"
#include "co_dcli.h"
char CoLogin::m_username[40] = "";
char CoLogin::m_password[40] = "";
char CoLogin::m_ucpassword[40] = "";
char CoLogin::m_group[40] = "";
pwr_mPrv CoLogin::m_priv = (pwr_mPrv)0;
login_mAttr CoLogin::m_attribute = (login_mAttr)0;
void CoLogin::activate_ok()
{
int sts;
message( "");
sts = get_values();
if ( ODD(sts)) {
if ( bc_success)
( bc_success) ( parent_ctx);
delete this;
return;
}
else {
message( "User not authorized");
printf( "User not authorized\n");
strcpy( (char *) &password, "");
}
}
void CoLogin::activate_cancel()
{
if ( bc_cancel)
(bc_cancel) ( parent_ctx);
delete this;
}
//
// Constructor
//
CoLogin::CoLogin( void *wl_parent_ctx,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)( void *),
void (* wl_bc_cancel)( void *),
pwr_tStatus *status) :
parent_ctx(wl_parent_ctx), bc_success(wl_bc_success), bc_cancel(wl_bc_cancel)
{
strcpy( name, wl_name);
strcpy( groupname, wl_groupname);
*status = 1;
}
//
// Destructor
//
CoLogin::~CoLogin()
{
}
//
// Check username and password and insert login infomation.
//
pwr_tStatus CoLogin::user_check( char *groupname, char *username, char *password)
{
pwr_tStatus sts;
unsigned int priv;
unsigned long attr = 0;
char cpassword[40];
strcpy( cpassword, UserList::pwcrypt( password));
sts = user_CheckUser( groupname, username, cpassword, &priv);
if ( EVEN(sts)) return sts;
insert_login_info( groupname, cpassword, username, priv, attr);
strcpy( m_ucpassword, password);
return LOGIN__SUCCESS;
}
//
// Inserts login info in global priv struct.
//
pwr_tStatus CoLogin::insert_login_info( char *groupname, char *password, char *username,
unsigned long priv, unsigned long attr)
{
strcpy( m_username, username);
strcpy( m_password, password);
strcpy( m_group, groupname);
m_priv = (pwr_mPrv)priv;
m_attribute = (login_mAttr)attr;
return LOGIN__SUCCESS;
}
pwr_tStatus CoLogin::get_login_info( char *groupname, char *password, char *username,
unsigned long *priv, unsigned long *attr)
{
if ( username)
strcpy( username, m_username);
if ( password)
strcpy( password, m_password);
if ( groupname)
strcpy( groupname, m_group);
if ( priv)
*priv = (unsigned long)m_priv;
if ( attr)
*attr = (unsigned long)m_attribute;
return LOGIN__SUCCESS;
}
/*
* Proview $Id: co_login.h,v 1.1 2008-06-24 06:51:43 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#ifndef co_login_h
#define co_login_h
#ifndef pwr_h
#include "pwr.h"
#endif
#ifndef pwr_privilege_h
#include "pwr_privilege.h"
#endif
typedef enum {
login_mAttr_Navigator = 1 << 0
} login_mAttr;
class CoLogin {
private:
static char m_username[40];
static char m_password[40];
static char m_ucpassword[40];
static char m_group[40];
static pwr_mPrv m_priv;
static login_mAttr m_attribute;
public:
void *parent_ctx;
char name[80];
void (*bc_success)( void *);
void (*bc_cancel)( void *);
char groupname[40];
char password[40];
CoLogin( void *wl_parent_ctx,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)( void *),
void (* wl_bc_cancel)( void *),
pwr_tStatus *sts);
virtual ~CoLogin();
void activate_ok();
void activate_cancel();
virtual pwr_tStatus get_values() {return 0;}
virtual void message( char *new_label) {}
static pwr_tStatus user_check( char *groupname, char *username, char *password);
static pwr_tStatus insert_login_info( char *groupname, char *password, char *username,
unsigned long priv, unsigned long attr);
static pwr_tStatus get_login_info( char *groupname, char *password, char *username,
unsigned long *priv, unsigned long *attr);
static unsigned long privilege() { return m_priv;}
static char *username() { return m_username;}
static char *ucpassword() { return m_ucpassword;}
};
#endif
!
! Proview $Id: co_login_msg.msg,v 1.1 2008-06-24 06:51:43 claes Exp $
! Copyright (C) 2005 SSAB Oxelösund AB.
!
! 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 the program, if not, write to the Free Software
! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
!
! wb_login_msg.msg -- <short description>
!
.facility LOGIN,320 /prefix = LOGIN__ ! Login
success <successful completion> /succ
usernotau <user not authorized> /error
userexist <user already exixts> /error
nomemory <no dynamic memory> /error
nouserlist <userlist not opened> /error
nouser <no such user> /error
userfile <unable to oper userlist data file> /error
nosave <nothing written in user data file> /info
nopriv <no privilege for attempted operation> /error
authfail <user authorization failure> /error
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment