小编joc*_*oce的帖子

Win32用户模拟好奇心

在codeproject上找到了一些允许用户模拟的示例代码.

此代码通过导入以下非托管Win32 API函数来工作:

[DllImport("advapi32.dll", SetLastError = true)]
private static extern int LogonUser(
    string lpszUserName,
    string lpszDomain,
    string lpszPassword,
    int dwLogonType,
    int dwLogonProvider,
    ref IntPtr phToken);

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int DuplicateToken(IntPtr hToken,int impersonationLevel,ref IntPtr hNewToken);

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool RevertToSelf();

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern bool CloseHandle(IntPtr handle);
Run Code Online (Sandbox Code Playgroud)

这些函数用于模拟目标用户,然后执行某些操作,然后还原模拟上下文.冒充用户是这样实现的:

if ( LogonUser(userName, domainName, password, LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT, ref token ) != 0 )
{
    if …
Run Code Online (Sandbox Code Playgroud)

c# windows authentication winapi

8
推荐指数
1
解决办法
3426
查看次数

将数组传递给用户输入的execvp()

我正在尝试将用户输入的参数传递给execvp().

到目前为止,我已经拆分了字符串.如果用户键入ls -a,temp则保存为"ls"和"-a",后跟NULL字符.我不太确定如何恰当地指出这一点execvp.在我看到它使用的例子中execvp(temp[position], temp).我知道我现在尝试这样做的方式是错误的,但我不确定如何正确地做到这一点!目前我遇到了分段错误.

int main(int argc, char *argv[]) 
{
    char line[124];
    int size = 124;
    char *temp = NULL;

    while(fgets(line, size, stdin) != NULL ) {
        if (strcmp(line, "exit\n") == 0) {
            exit(EXIT_SUCCESS);
        }
        temp = strtok(line, " ");
        while (temp != NULL) {
            printf("%s\n", temp);
            temp = strtok(NULL, " ");
        }
        execvp(temp, &temp);    
    }
    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

c execvp

8
推荐指数
1
解决办法
1万
查看次数

在CentOS 6上安装pg gem

我正在尝试使用ruby on rails和postgres设置我的VPS(CentOS 6.4).

我安装了ruby(2.1.0p0),rails(4.1.0)和postgresql(9.3.4)没有问题.

当我尝试创建新的rails应用程序(rails new new_app -d postgresql)时,它会在安装pg gem时停止.我查看了有关此错误的所有SO帖子,并尝试了我能找到的所有内容.最建议的是运行"yum install postgresql-devel"并仍然无法正常工作.

您可以在下面找到ssh输出和mkmf.log.如果需要更多信息,请告诉我......


产量

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.

/home/deploy/.rvm/rubies/ruby-2.1.0/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided …

postgresql gem centos ruby-on-rails centos6

8
推荐指数
3
解决办法
5129
查看次数

多态如何在C#中使用未定义的中间类型?

在下面的代码中,我原本期望调用a.Generate(v)会导致调用V.Visit(A a),因为当调用Generate是this类型A.Hoewever时,它看起来this像是一个Inter代替.

是否有可能具有不明确地执行(相同)的方法在两个预期的行为AB与仅在共享基类?如果是这样,怎么能实现呢?

using System;
using System.Diagnostics;

namespace Test {
    class Base {}
    class Inter: Base {
        public virtual void Generate(V v) {
            // `Visit(Base b)` and not `Visit(A a)` is called when calling
            // A.Generate(v). Why?
            v.Visit(this);
        }
    }

    class A: Inter {}
    class B: Inter {}

    class V {
        public void Visit(Base b) { throw new NotSupportedException(); }
        public void Visit(A a)    { Trace.WriteLine("a"); …
Run Code Online (Sandbox Code Playgroud)

c# polymorphism

7
推荐指数
1
解决办法
462
查看次数

在slidify中自定义幻灯片布局

我有兴趣在index.Rmd文件中为不同的幻灯片使用不同的布局.复制此处和下面提供的模板后,我在我的assets/layouts文件夹中创建了一个.html文件.

<slide class="{{ class }}" id="{{ id }}">
  <hgroup>
    {{{ header }}}
  </hgroup>
  <article>
    <hr noshade size=4 color='red'>  
    {{{ content }}}  
    <div class='left' style='float:left;width:48%'>
     {{{ left }}}
    </div>    
    <div class='right' style='float:right;width:48%'>
     {{{ right }}}
    </div>
  </article>
</slide>
Run Code Online (Sandbox Code Playgroud)

到目前为止,仍然不清楚:

1)为什么我牌组中的幻灯片是空白的,并且没有显示以下任何内容:

---
#testing
hello

*** left

- point a
- point b
- point c

*** right

- point a
- point b
- point c
Run Code Online (Sandbox Code Playgroud)

2)如何从我的资产文件夹中为单个幻灯片而不是整个卡组"调用"自定义布局

slidify

7
推荐指数
1
解决办法
2196
查看次数

C++ ostream和ofstream转换

我的代码有一个ostream由各种模块累积并最终显示到控制台的对象.我也想将这个ostream对象写入一个文件,但我是否必须使用一个ofstream对象重写所有代码,或者有一种方法可以将一个转换为另一个(可能通过stringstream?)

例如,我现有的许多功能都是这样的

ostream& ClassObject::output(ostream& os) const
{
    os << "Details";
    return os;
}
Run Code Online (Sandbox Code Playgroud)

我可以用ofstream对象作为参数调用此函数,并让该ofstream对象累积信息吗?

c++ ofstream

7
推荐指数
1
解决办法
1万
查看次数

Json.NET:反序列化json数组

我正在尝试使用Json.NET处理JSON结构并遇到一些问题:

当JSON包含未命名的数组时,我的类不起作用.

Json示例:

{
    "graph_property" : [{
            "name" : "calculation_method",
            "value" : "Arithmetic"
        }, {
            "name" : "graph_type",
            "value" : "TIME"
        }
    ],
    "measurement" : [{
            "id" : "9997666",
            "alias" : "Measurement (TxP)[IE]-Home Page - Total Time (seconds)",
            "bucket_data" : [{
                    "name" : "2013-MAR-18 12:00 AM",
                    "id" : 1,
                    "perf_data" : {
                        "value" : "2.244",
                        "unit" : "seconds"
                    },
                    "avail_data" : {
                        "value" : "99.67",
                        "unit" : "percent"
                    },
                    "data_count" : {
                        "value" : "299",
                        "unit" : "#"
                    }
                } …
Run Code Online (Sandbox Code Playgroud)

c# json json.net

7
推荐指数
2
解决办法
4万
查看次数

如何在C中为客户端提供特定的IP地址

我试图在C中实现一个简单的客户端和服务器,我无法在网上找到如何为客户端设置特定IP地址的示例.这是我到目前为止所得到的:

sockfd = socket(PF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
{
    <some code to handle error>
}
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr(<addressOfTheServer>);
address.sin_port = htons(<portToConnectToServer>);
len = sizeof(address);

int result = connect(sockfd, (struct sockaddr *)&address, len);
Run Code Online (Sandbox Code Playgroud)

在服务器端,我检查客户端IP地址,我总是得到127.0.0.1

我想改变一些不同的东西.

c sockets client-server ip-address

7
推荐指数
1
解决办法
6万
查看次数

输出对齐的列

我正在学习C++.我在格式化程序输出时遇到问题.我想打印完全对齐的列,但到目前为止我不能这样做,这是我的代码:

int main()
{
    employee employees[5];

    employees[0].setEmployee("Stone", 35.75, 053);
    employees[1].setEmployee("Rubble", 12, 163);
    employees[2].setEmployee("Flintstone", 15.75, 97);
    employees[3].setEmployee("Pebble", 10.25, 104);
    employees[4].setEmployee("Rockwall", 22.75, 15);

    printEmployees(employees, 5);

    return 0;
}

// print the employees in my array
void printEmployees(employee employees[], int number)
{
    int i;

    for (i=0; i<number; i++) {
        employees[i].printEmployee();// this is the method that give me problems
    }
    cout << "\n";
}
Run Code Online (Sandbox Code Playgroud)

在班级员工中我有print员工方法:

void printEmployee() const
{
    cout << fixed;
    cout << surname << setw(10) << empNumber << "\t" << setw(4) << …
Run Code Online (Sandbox Code Playgroud)

c++ cout

6
推荐指数
2
解决办法
6万
查看次数

Fusion绑定后策略忽略bindingRedirect

我有一个SignalR和Ext.net的项目.两者都需要Newtonsoft.Json.

SignalR需要Newtonsoft.Json 4.5.0.0,Ext.net需要4.0.8.0.

我的绑定重定向根本不起作用.在我的web.config中

<dependentAssembly>
  <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
  <bindingRedirect oldVersion="4.0.8.0" newVersion="4.5.0.0"/>
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

但是当它结束时

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=4.0.8.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
 (Fully-specified)
LOG: Appbase = file:///C:/Users/*****/Documents/Visual Studio 2012/Projects/QuotaBuilder/branches/1Install/QMSSite/
LOG: Initial PrivatePath = C:\Users\*****\Documents\Visual Studio 2012\Projects\QuotaBuilder\branches\1Install\QMSSite\bin
Calling assembly : Ext.Net, Version=1.6.0.1867, Culture=neutral, PublicKeyToken=2e12ce3d0176cd87.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\*****\Documents\Visual Studio 2012\Projects\QuotaBuilder\branches\1Install\QMSSite\web.config
LOG: Using host configuration file: \\pacrl-fsrv02\userdata$\*****\My Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy …

c# fusion assembly-binding-redirect

6
推荐指数
1
解决办法
597
查看次数