2012-04-28 55 views
2

我試圖在遠程linux服務器上設置一個git存儲庫,這樣我就可以通過ssh連接並共享單個登錄名朋友以一種相當安全的方式。我遇到了問題,因爲我的sshd通過設置在ssh config中的FORCE_COMMAND調用了雙重安全(指向'/usr/sbin/login_duo')。我決定解決這個問題。所以我查了一下git代碼,並拿起了足夠的C來進行更改(在shell.c中),以便它忽略/ usr/sbin/login_duo調用並調用run_shell(),這會創建正常的git-shell提示符。 (現在我敢肯定,這不是正確的解決方案,因爲我不希望一個git clone調用在shell結束了,但這個問題似乎仍然有效)git-shell在提示符下處理的命令不會執行任何操作(只是掛起)

無論如何,我設法讓git>提示出現,但似乎並沒有處理我輸入的輸入(一旦我輸入了輸入/退出然後回車)。我希望它能打印出「git got x」,但它只是坐在那裏。有任何想法嗎?

  fprintf(stderr, "git> "); 
      if (strbuf_getline(&line, stdin, '\n') == EOF) { 
        fprintf(stderr, "\n"); 
        strbuf_release(&line); 
        break; 
      } 
      fprintf(stderr, "git got %s\n", line); 

實施例:

[email protected]:~/projects/test$ git clone ssh://[email protected]/home/git/repo1 
Cloning into repo1... 
[email protected]'s password: 
login_duo ignored <-- where I split off and call the shell function 
git> exit 
<--hangs-->` 

回答

2

line的類型爲:

struct strbuf { 
    size_t alloc; 
    size_t len; 
    char *buf; 
}; 


fprintf(stderr, "git got %s\n", line)應該產生沿着線編譯器警告:
warning: format ‘%s’ expects argument of type ‘char *’...

忽略此警告並運行代碼很可能會導致段錯誤或其他崩潰。

試試這個:

fprintf(stderr, "git got %s\n", line.buf); 
+0

有趣的,謝謝!那一定是它;我原本以爲它會在最糟糕的時候給我一個內存位置。我一定錯過了這個警告[我在嘗試構建tcl代碼時總會遇到一個錯誤,所以必須不幸錯過它]。 – Egwor 2012-04-28 14:59:42

+1

結果未定義,取決於'alloc'&'len'的值。例如,如果'alloc'爲零,你不會得到太多的東西,但它不會崩潰;) – violet313 2012-04-28 15:12:48

相關問題