Commit 77410bee authored by claes's avatar claes

Login and logout added

parent b9e9e44e
/*
* Proview $Id: xtt_xnav.cpp,v 1.38 2008-05-29 15:00:37 claes Exp $
* Proview $Id: xtt_xnav.cpp,v 1.39 2008-06-24 08:11:28 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -35,6 +35,7 @@
#include "co_time.h"
#include "co_api.h"
#include "co_msg.h"
#include "co_syi.h"
#include "pwr_baseclasses.h"
#include "rt_xnav_msg.h"
#include "flow.h"
......@@ -1494,6 +1495,15 @@ int XNav::get_all_collect_objects( pwr_sAttrRef **attrref, int **is_attr)
return 1;
}
int XNav::is_authorized( unsigned int access, int msg)
{
if (!(priv & access)) {
if ( msg)
message( 'I', "Not authorized for this operation");
return 0;
}
return 1;
}
......@@ -1637,6 +1647,9 @@ int XNav::brow_cb( FlowCtx *ctx, flow_tEvent event)
if ( xnav->closing_down)
return 1;
if ( !xnav->is_authorized())
return 1;
xnav->message( ' ', null_str);
try {
switch ( event->event) {
......@@ -3445,6 +3458,9 @@ int XNav::init_brow_base_cb( FlowCtx *fctx, void *client_data)
xnav->load_ev_from_opplace();
xnav->login_from_opplace();
}
else
xnav->login();
return 1;
}
......@@ -3493,6 +3509,8 @@ int XNav::login_from_opplace()
int sts;
unsigned int privilege;
char systemgroup[80];
pwr_sSecurity sec;
char username[80];
sts = gdh_ObjidToPointer( gbl.UserObject, (void **) &user_p);
if ( EVEN(sts)) return sts;
......@@ -3501,20 +3519,72 @@ int XNav::login_from_opplace()
sizeof(systemgroup));
if ( EVEN(sts)) return sts;
sts = user_GetUserPriv( systemgroup, user_p->UserName, &privilege);
priv = base_priv = 0;
sts = gdh_GetSecurityInfo( &sec);
if ( ODD(sts) && sec.XttUseOpsysUser)
syi_UserName( username, sizeof(username));
else
strcpy( username, user_p->UserName);
sts = user_GetUserPriv( systemgroup, username, &privilege);
if ( EVEN(sts)) {
// Failiure, set read priv
priv = pwr_mPrv_RtRead;
base_priv = pwr_mPrv_RtRead;
priv = base_priv = 0;
return sts;
}
strcpy( user, user_p->UserName);
strcpy( base_user, user_p->UserName);
priv = privilege;
base_priv = privilege;
strcpy( user, username);
strcpy( base_user, username);
priv = base_priv = privilege;
return XNAV__SUCCESS;
}
int XNav::login()
{
int sts;
unsigned int privilege;
char systemgroup[80];
pwr_sSecurity sec;
char username[80];
priv = base_priv = 0;
sts = gdh_GetSecurityInfo( &sec);
if ( EVEN(sts)) return sts;
if ( sec.XttUseOpsysUser) {
syi_UserName( username, sizeof(username));
sts = gdh_GetObjectInfo ( "pwrNode-System.SystemGroup", &systemgroup,
sizeof(systemgroup));
if ( EVEN(sts)) return sts;
sts = user_GetUserPriv( systemgroup, username, &privilege);
if ( EVEN(sts)) return sts;
strcpy( user, username);
strcpy( base_user, username);
priv = base_priv = privilege;
return XNAV__SUCCESS;
}
priv = base_priv = sec.DefaultXttPriv;
return XNAV__SUCCESS;
}
void XNav::open_login()
{
pwr_tCmd cmd;
strcpy( cmd, "login");
command( cmd);
}
void XNav::logout()
{
pwr_tCmd cmd;
strcpy( cmd, "logout");
command( cmd);
}
int XNav::init_brow_collect_cb( BrowCtx *ctx, void *client_data)
{
XNav *xnav = (XNav *) client_data;
......
/*
* Proview $Id: xtt_xnav.h,v 1.22 2008-04-25 11:28:54 claes Exp $
* Proview $Id: xtt_xnav.h,v 1.23 2008-06-24 08:11:28 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -74,6 +74,10 @@ extern "C" {
#include "xtt_logging.h"
#endif
#ifndef pwr_privilege_h
#include "pwr_privilege.h"
#endif
#define xnav_cVersion "X3.0b"
#define XNAV_BROW_MAX 25
#define XNAV_LOGG_MAX 10
......@@ -97,6 +101,7 @@ class CLog;
class XttGe;
class RtTrace;
class XttFileview;
class CoLogin;
typedef enum {
xnav_mOpen_All = ~0,
......@@ -342,7 +347,13 @@ class XNav {
virtual GeCurve *gecurve_new( char *name, char *filename, GeCurveData *data,
int pos_right) {return 0;}
virtual XttFileview *fileview_new( pwr_tOid oid, char *title, char *dir, char *pattern,
int type, char *target_attr, char *trigger_attr) {return 0;}
int type, char *target_attr, char *trigger_attr,
char *filetype) {return 0;}
virtual CoLogin *login_new( char *wl_name,
char *wl_groupname,
void (* wl_bc_success)( void *),
void (* wl_bc_cancel)( void *),
pwr_tStatus *status) { return 0;}
virtual void bell( int time) {}
void start_trace( pwr_tObjid Objid, char *object_str);
......@@ -391,6 +402,10 @@ class XNav {
int menu_tree_delete( char *name);
int load_ev_from_opplace();
int login_from_opplace();
int login();
void open_login();
void logout();
int is_authorized( unsigned int access = pwr_mAccess_AllRt, int msg = 1);
static char *get_message( int sts);
int show_object_as_struct(
pwr_tObjid objid,
......
/*
* Proview $Id: xtt_xnav_command.cpp,v 1.34 2008-04-25 11:29:21 claes Exp $
* Proview $Id: xtt_xnav_command.cpp,v 1.35 2008-06-24 08:11:28 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -57,6 +57,7 @@
#include "co_dcli_msg.h"
#include "rt_xnav_msg.h"
#include "co_xhelp.h"
#include "co_login.h"
#include "glow_curvectx.h"
#include "ge_curve.h"
......@@ -210,7 +211,7 @@ dcli_tCmdTable xnav_command_table[] = {
"/NAVIGATOR", "/CENTER", "/OBJECT", "/NEW",
"/INSTANCE", "/COLLECT", "/FOCUS", "/INPUTEMPTY",
"/ENTRY", "/TITLE", "/ACCESS", "/CLASSGRAPH", "/BYPASS",
"/CLOSEBUTTON", "/TARGET", "/TRIGGER", "/TYPE", ""}
"/CLOSEBUTTON", "/TARGET", "/TRIGGER", "/TYPE", "/FTYPE", ""}
},
{
"CLOSE",
......@@ -536,6 +537,20 @@ static int xnav_define_func( void *client_data,
return sts;
}
static void xnav_login_success_bc( void *ctx)
{
XNav *xnav = (XNav *)ctx;
char msg[80];
CoLogin::get_login_info( 0, 0, xnav->user, (unsigned long *)&xnav->priv, 0);
sprintf( msg, "User %s logged in", xnav->user);
xnav->message('I', msg);
}
static void xnav_login_cancel_bc(void *xnav)
{
}
static int xnav_login_func( void *client_data,
void *client_flag)
{
......@@ -547,9 +562,15 @@ static int xnav_login_func( void *client_data,
unsigned int priv;
char msg[80];
sts = gdh_GetObjectInfo ( "pwrNode-System.SystemGroup", &systemgroup,
sizeof(systemgroup));
if ( EVEN(sts)) return sts;
if ( EVEN( dcli_get_qualifier( "dcli_arg1", arg1_str, sizeof(arg1_str))))
{
xnav->message('E',"Syntax error");
xnav->login_new( "PwR Login", systemgroup, xnav_login_success_bc,
xnav_login_cancel_bc, &sts);
return 1;
}
if ( EVEN( dcli_get_qualifier( "dcli_arg2", arg2_str, sizeof(arg2_str))))
......@@ -557,9 +578,6 @@ static int xnav_login_func( void *client_data,
xnav->message('E',"Syntax error");
return 1;
}
sts = gdh_GetObjectInfo ( "pwrNode-System.SystemGroup", &systemgroup,
sizeof(systemgroup));
if ( EVEN(sts)) return sts;
cdh_ToLower( arg1_str, arg1_str);
cdh_ToLower( arg2_str, arg2_str);
......@@ -1741,7 +1759,9 @@ static int xnav_show_func( void *client_data,
if ( strcmp( xnav->user, "") == 0)
{
xnav->message('I', "Not logged in");
user_RtPrivToString( xnav->priv, priv_str, sizeof(priv_str));
sprintf( msg, "Not logged in (%s)", priv_str);
xnav->message('I', msg);
}
else
{
......@@ -3061,6 +3081,8 @@ static int xnav_open_func( void *client_data,
pwr_tAName trigger_str;
char title_str[80];
char type_str[80];
char filetype_str[80];
char *filetype_p = 0;
int type;
char *s;
pwr_tAttrRef aref;
......@@ -3091,6 +3113,9 @@ static int xnav_open_func( void *client_data,
else
type = fileview_eType_Open;
if ( ODD( dcli_get_qualifier( "/FTYPE", filetype_str, sizeof(filetype_str))))
filetype_p = filetype_str;
if ( EVEN( dcli_get_qualifier( "/TITLE", title_str, sizeof(title_str)))) {
if ( type == fileview_eType_Open)
strcpy( title_str, "Open File");
......@@ -3110,7 +3135,7 @@ static int xnav_open_func( void *client_data,
}
fileview = xnav->fileview_new( aref.Objid, title_str, dir_str, file_str, type,
target_str, trigger_str);
target_str, trigger_str, filetype_p);
}
else
xnav->message('E',"Syntax 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