Commit 62ac2af5 authored by claes's avatar claes

Moved to co

parent 912ee851
!
! Proview $Id: wb_login_msg.msg,v 1.2 2005-09-01 14:58:00 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
/*
* Proview $Id: wb_login_gtk.cpp,v 1.1 2007-01-04 07:29:02 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 "wb_login_msg.h"
#include "wb_login_gtk.h"
#include "wb_utl_api.h"
#include "co_api.h"
#include "co_dcli.h"
//
// Callback from the pushbutton.
//
void WLoginGtk::activate_ok( GtkWidget *w, gpointer data)
{
WLogin *loginctx = (WLogin *)data;
loginctx->activate_ok();
}
//
// Callback from the pushbutton.
//
void WLoginGtk::activate_cancel( GtkWidget *w, gpointer data)
{
WLogin *loginctx = (WLogin *)data;
loginctx->activate_cancel();
}
//
// Callback when value changed.
//
void WLoginGtk::valchanged_passwordvalue( GtkWidget *w, gpointer data)
{
WLogin *loginctx = (WLogin *)data;
gtk_widget_activate( ((WLoginGtk *)loginctx)->widgets.okbutton);
}
//
// Callback when value changed.
//
void WLoginGtk::valchanged_usernamevalue( GtkWidget *w, gpointer data)
{
WLogin *loginctx = (WLogin *)data;
gtk_widget_grab_focus( ((WLoginGtk *)loginctx)->widgets.passwordvalue);
}
static gint login_delete_event( GtkWidget *w, GdkEvent *event, gpointer data)
{
WLogin *loginctx = (WLogin *)data;
loginctx->activate_cancel();
return TRUE;
}
//
// Constructor
//
WLoginGtk::WLoginGtk( void *wl_parent_ctx,
GtkWidget *wl_parent_wid,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)(),
void (* wl_bc_cancel)(),
pwr_tStatus *status) :
WLogin(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);
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);
#if 0
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", topLevelShellGtkWidgetClass, 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 = MrmFetchGtkWidgetOverride(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);
#endif
*status = 1;
}
//
// Destructor
//
WLoginGtk::~WLoginGtk()
{
/* Destroy the widget */
gtk_widget_destroy( widgets.toplevel);
}
//
// Get values in username and password.
//
pwr_tStatus WLoginGtk::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 WLoginGtk::message( char *new_label)
{
gtk_label_set_text( GTK_LABEL(widgets.label), new_label);
}
/*
* Proview $Id: wb_login_gtk.h,v 1.1 2007-01-04 07:29:02 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 wb_login_gtk_h
#define wb_login_gtk_h
#ifndef wb_login_h
#include "wb_login.h"
#endif
struct login_widgets
{
GtkWidget *toplevel;
GtkWidget *login_window;
GtkWidget *label;
GtkWidget *okbutton;
GtkWidget *usernamevalue;
GtkWidget *passwordvalue;
};
class WLoginGtk : public WLogin {
public:
GtkWidget *parent_wid;
struct login_widgets widgets;
WLoginGtk( void *wl_parent_ctx,
GtkWidget *wl_parent_wid,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)(),
void (* wl_bc_cancel)(),
pwr_tStatus *sts);
~WLoginGtk();
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: wb_login_motif.cpp,v 1.1 2007-01-04 07:29:02 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 "wb_login_motif.h"
#include "wb_utl_api.h"
#include "co_api.h"
#include "co_dcli.h"
#define BEEP putchar( '\7' );
//
// Callback from the pushbutton.
//
void WLoginMotif::activate_ok( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data)
{
loginctx->activate_ok();
}
//
// Callback from the pushbutton.
//
void WLoginMotif::activate_cancel( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data)
{
loginctx->activate_cancel();
}
void WLoginMotif::create_label( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data)
{
((WLoginMotif *)loginctx)->widgets.label = w;
}
void WLoginMotif::create_adb( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data)
{
((WLoginMotif *)loginctx)->widgets.adb = w;
}
void WLoginMotif::create_usernamevalue( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data)
{
((WLoginMotif *)loginctx)->widgets.usernamevalue = w;
}
void WLoginMotif::create_passwordvalue( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data)
{
((WLoginMotif *)loginctx)->widgets.passwordvalue = w;
}
//
// Callback when value changed.
//
void WLoginMotif::valchanged_passwordvalue( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data)
{
char *value;
int sts;
char *s;
if ( ((WLoginMotif *)loginctx)->widgets.passwordvalue == 0)
return;
value = XmTextGetString( ((WLoginMotif *)loginctx)->widgets.passwordvalue);
if ( *value == 0)
return;
s = strrchr( value, 10);
if (s == 0) {
strcat(loginctx->password, value);
XtFree( value);
XmTextSetString( ((WLoginMotif *)loginctx)->widgets.passwordvalue, "");
return;
}
loginctx->message( "");
sts = loginctx->get_values();
if ( ODD(sts)) {
if (loginctx->bc_success != NULL)
(loginctx->bc_success) ();
XtFree( value);
delete loginctx;
return;
}
else {
loginctx->message( "User not authorized");
BEEP;
printf( "User not authorized\n");
XmTextSetString( ((WLoginMotif *)loginctx)->widgets.passwordvalue, "");
strcpy(loginctx->password, "");
XtFree( value);
}
}
//
// Callback when value changed.
//
void WLoginMotif::valchanged_usernamevalue( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data)
{
char *value;
char *s;
if ( ((WLoginMotif *)loginctx)->widgets.usernamevalue == 0)
return;
value = XmTextGetString( ((WLoginMotif *)loginctx)->widgets.usernamevalue);
if ( *value == 0)
return;
s = strrchr( value, 10);
if (s == 0)
{
XtFree( value);
return;
}
loginctx->message( "");
strcpy( s, s + 1);
XmTextSetString( ((WLoginMotif *)loginctx)->widgets.usernamevalue, value);
XtFree( value);
/* Focus password */
XtSetKeyboardFocus( ((WLoginMotif *)loginctx)->widgets.toplevel,
((WLoginMotif *)loginctx)->widgets.passwordvalue);
}
//
// Constructor
//
WLoginMotif::WLoginMotif( void *wl_parent_ctx,
Widget wl_parent_wid,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)(),
void (* wl_bc_cancel)(),
pwr_tStatus *status) :
WLogin(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
//
WLoginMotif::~WLoginMotif()
{
/* Destroy the widget */
XtDestroyWidget( widgets.toplevel) ;
}
//
// Get values in username and password.
//
pwr_tStatus WLoginMotif::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 WLoginMotif::message( char *new_label)
{
Arg args[2];
XtSetArg(args[0], XmNlabelString,
XmStringCreateLtoR( new_label , "ISO8859-1"));
XtSetValues( widgets.label, args, 1);
}
/*
* Proview $Id: wb_login_motif.h,v 1.1 2007-01-04 07:29:02 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 wb_login_motif_h
#define wb_login_motif_h
#ifndef wb_login_h
#include "wb_login.h"
#endif
struct login_widgets
{
Widget toplevel;
Widget login_window;
Widget label;
Widget adb;
Widget usernamevalue;
Widget passwordvalue;
};
class WLoginMotif : public WLogin {
public:
Widget parent_wid;
struct login_widgets widgets;
WLoginMotif( void *wl_parent_ctx,
Widget wl_parent_wid,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)(),
void (* wl_bc_cancel)(),
pwr_tStatus *sts);
~WLoginMotif();
pwr_tStatus get_values();
void message( char *new_label);
static void activate_ok( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data);
static void activate_cancel( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data);
static void create_label( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data);
static void create_adb( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data);
static void create_usernamevalue( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data);
static void create_passwordvalue( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data);
static void valchanged_passwordvalue( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data);
static void valchanged_usernamevalue( Widget w, WLogin *loginctx, XmAnyCallbackStruct *data);
};
#endif
/*
* Proview $Id: wb_login.cpp,v 1.1 2007-01-04 07:29:03 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 "wb_login.h"
#include "wb_utl_api.h"
#include "co_api.h"
#include "co_dcli.h"
pwr_dExport login_sPrv login_prv;
void WLogin::activate_ok()
{
int sts;
message( "");
sts = get_values();
if ( ODD(sts)) {
if ( bc_success)
( bc_success) ();
delete this;
return;
}
else {
message( "User not authorized");
printf( "User not authorized\n");
strcpy( (char *) &password, "");
}
}
void WLogin::activate_cancel()
{
if ( bc_cancel)
(bc_cancel) ();
delete this;
}
//
// Constructor
//
WLogin::WLogin( void *wl_parent_ctx,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)(),
void (* wl_bc_cancel)(),
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
//
WLogin::~WLogin()
{
}
//
// Check username and password and insert login infomation.
//
pwr_tStatus WLogin::user_check( char *groupname, char *username, char *password)
{
pwr_tStatus sts;
unsigned int priv;
unsigned long attr = 0;
sts = user_CheckUser( groupname, username, password, &priv);
if ( EVEN(sts)) return sts;
insert_login_info( groupname, password, username, priv, attr);
return LOGIN__SUCCESS;
}
//
// Inserts login info in global priv struct.
//
pwr_tStatus WLogin::insert_login_info( char *groupname, char *password, char *username,
unsigned long priv, unsigned long attr)
{
strcpy(login_prv.username, username);
strcpy(login_prv.password, password);
strcpy(login_prv.group, groupname);
login_prv.priv = (pwr_mPrv)priv;
login_prv.attribute = (login_mAttr)attr;
return LOGIN__SUCCESS;
}
//
// Writes a userlist.
//
pwr_tStatus WLogin::show_priv()
{
printf("\n");
printf("Authorized privileges for User: %s\n", login_prv.username);
printf(" SystemGroup: %s\n", login_prv.group);
if ( login_prv.priv & pwr_mPrv_RtRead)
printf(" RtRead\n");
if ( login_prv.priv & pwr_mPrv_RtWrite)
printf(" RtWrite\n");
if ( login_prv.priv & pwr_mPrv_DevRead)
printf(" DevRead\n");
if ( login_prv.priv & pwr_mPrv_DevPlc)
printf(" DevPlc\n");
if ( login_prv.priv & pwr_mPrv_DevConfig)
printf(" DevConfig\n");
if ( login_prv.priv & pwr_mPrv_DevClass)
printf(" DevClass\n");
return LOGIN__SUCCESS;
}
/*
* Proview $Id: wb_login.h,v 1.4 2007-01-04 07:29:03 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 wb_login_h
#define wb_login_h
#ifndef pwr_h
#include "pwr.h"
#endif
#ifndef pwr_privilege_h
#include "pwr_privilege.h"
#endif
typedef struct login_s_Prv login_sPrv;
typedef enum {
login_mAttr_Navigator = 1 << 0
} login_mAttr;
pwr_dImport login_sPrv login_prv;
struct login_s_Prv {
char username[40];
char password[40];
char group[40];
pwr_mPrv priv;
login_mAttr attribute;
};
class WLogin {
public:
void *parent_ctx;
char name[80];
void (*bc_success)();
void (*bc_cancel)();
char groupname[40];
char password[40];
WLogin( void *wl_parent_ctx,
char *wl_name,
char *wl_groupname,
void (* wl_bc_success)(),
void (* wl_bc_cancel)(),
pwr_tStatus *sts);
virtual ~WLogin();
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 show_priv();
};
#endif
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