• File: writeln() and line endings

    From Nightfox@VERT/DIGDIST to Digital Man on Sat Apr 26 13:45:04 2025
    Hi DM,

    Recently I've been working on trying to get SlyEdit to behave in a way that it could be used to edit general files (and specifically, SSH keys & such, as it seems that might be useful at some point). I'm at a point where I've started doing a test to make sure SlyEdit is saving the file correctly:

    There's a system set up where I have an SSH key shared with it so that I can SSH to it without entering a password, and my test is basically this:
    1. Move my local ~/.ssh/id_rsa to a different place, and open it in a text editor (so I can copy it)
    2. Edit ~/.ssh/id_rsa with SlyEdit (which at this point is a new file), then copy the contents of id_rsa from the text editor and paste it into my terminal session with SlyEdit, and save the file
    3. Try to SSH to that remote system from my BBS machine and see if it's successful

    After this, id_rsa looks fine, but SSH authentication fails (ssh says it loads id_rsa but it says "error in libcrypto" and prompts me for a password). I've found that the reason seems to be id_rsa has DOS-style line endings (with \r\n) - I verified with a hex editor and saw that was indeed the case. If I convert id_rsa with dos2unix, I'm able to successfully SSH to the other PC.

    SlyEdit is writing the lines using the File.writeln() function. I'm running my BBS on Linux; should writeln() be expected to write with \n line endings on Linux?

    As a test, I tried having SlyEdit use write() (instead of writln() and append "\n" at the end of each line, but the lines in id_rsa still end with \r\n. I also tried opening the file with binary (as "wb") but the file still had \r\n line endings.

    Taking a step back, should I even be worrying about the line endings when saving files with SlyEdit? I'm not sure what the best course of action is here.

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From nelgin@VERT/EOTLBBS to All on Sat Apr 26 19:34:21 2025
    On Sat, 26 Apr 2025 13:45:04 -0700
    "Nightfox" (VERT/DIGDIST) <VERT/DIGDIST!Nightfox@endofthelinebbs.com>
    wrote:

    Hi DM,

    Recently I've been working on trying to get SlyEdit to behave in a
    way that it could be used to edit general files (and specifically,
    SSH keys & such, as it seems that might be useful at some point).
    I'm at a point where I've started doing a test to make sure SlyEdit
    is saving the file correctly:

    There's a system set up where I have an SSH key shared with it so
    that I can SSH to it without entering a password, and my test is
    basically this: 1. Move my local ~/.ssh/id_rsa to a different place,
    and open it in a text editor (so I can copy it) 2. Edit ~/.ssh/id_rsa
    with SlyEdit (which at this point is a new file), then copy the
    contents of id_rsa from the text editor and paste it into my terminal
    session with SlyEdit, and save the file 3. Try to SSH to that remote
    system from my BBS machine and see if it's successful

    After this, id_rsa looks fine, but SSH authentication fails (ssh says
    it loads id_rsa but it says "error in libcrypto" and prompts me for a password). I've found that the reason seems to be id_rsa has
    DOS-style line endings (with \r\n) - I verified with a hex editor and
    saw that was indeed the case. If I convert id_rsa with dos2unix, I'm
    able to successfully SSH to the other PC.

    SlyEdit is writing the lines using the File.writeln() function. I'm
    running my BBS on Linux; should writeln() be expected to write with
    \n line endings on Linux?

    As a test, I tried having SlyEdit use write() (instead of writln()
    and append "\n" at the end of each line, but the lines in id_rsa
    still end with \r\n. I also tried opening the file with binary (as
    "wb") but the file still had \r\n line endings.

    Taking a step back, should I even be worrying about the line endings
    when saving files with SlyEdit? I'm not sure what the best course of
    action is here.

    I'm not sure if this helps, but I have a modified version of
    user_settings.js that allows you to create/edit/delete ssh keys. I just
    took the rsa key from my Linux box and used the option in the setting
    editor which used FSEditor to save the file.

    If you want to try, I put it at https://www.endofthelinebbs.com/user_settings.js

    You'll want to create a text.ini entry so you can see the option. I
    have all of mine modified but you can try this.

    UserDefaultsPassword: " @~\1n\1h\1y(W)~W@ \1bChange Password or Signature @~\x01n\x01h\x01y(O)~O@ \x01bAdd, Change, or Delete SSH Key\r\n"


    and, of course, alter it to suit.

    I think I remember the SlyEdit saves the text already wrapped but
    FSEditor doesn't? You'll maybe want to check the user's sshkey file.
    --
    End Of The Line BBS - Plano, TX
    telnet endofthelinebbs.com 23
    ---
    þ Synchronet þ End Of The Line BBS - endofthelinebbs.com
  • From Digital Man@VERT to Nightfox on Sat Apr 26 18:26:04 2025
    Re: File: writeln() and line endings
    By: Nightfox to Digital Man on Sat Apr 26 2025 01:45 pm

    After this, id_rsa looks fine, but SSH authentication fails (ssh says it loads id_rsa but it says "error in libcrypto" and prompts me for a password). I've found that the reason seems to be id_rsa has DOS-style line endings (with \r\n) - I verified with a hex editor and saw that was indeed the case. If I convert id_rsa with dos2unix, I'm able to successfully SSH to the other PC.

    SlyEdit is writing the lines using the File.writeln() function. I'm running my BBS on Linux; should writeln() be expected to write with \n line endings on Linux?

    On Windows, File.writeln() will append either "\n" or "\r\n" depending on how the file was opened. If it was opened in text mode (the "t" open flag), then "\r\n" is used.

    On Linux, the "t" open mode flag is ignored and File.writeln() will always save the text with "\n" appended. Example:

    var f = new File("test.blah");
    f.open("w");
    f.writeln();

    Creates a file with a single byte:

    $ hd /sbbs/ctrl/test.blah
    00000000 0a |.|
    00000001

    If your edited file is ending up with CRLF terminated lines, that could just be the function of the console.editfile() method (if you're using that) and the underlying C++ methods that post-process the edited the file.
    --
    digital man (rob)

    Breaking Bad quote #7:
    [Want another beer?] "Does the Pope shit in his hat?" - Hank Schrader
    Norco, CA WX: 54.4øF, 70.0% humidity, 5 mph SW wind, 0.21 inches rain/24hrs
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Sun Apr 27 17:27:58 2025
    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Sat Apr 26 2025 06:26 pm

    On Windows, File.writeln() will append either "\n" or "\r\n" depending on how the file was opened. If it was opened in text mode (the "t" open flag), then "\r\n" is used.

    On Linux, the "t" open mode flag is ignored and File.writeln() will always save the text with "\n" appended. Example:

    var f = new File("test.blah");
    f.open("w");
    f.writeln();

    Creates a file with a single byte:

    $ hd /sbbs/ctrl/test.blah
    00000000 0a |.| 00000001

    I was able to confirm that.

    If your edited file is ending up with CRLF terminated lines, that could just be the function of the console.editfile() method (if you're using that) and the underlying C++ methods that post-process the edited the file.

    I am using console.editfile() to edit the file. It seems it is indeed console.editfile() that results in the line endings being \r\n.

    In my test, after creating id_rsa using console.editfile(), SSH fails to authenticate me, which seems to me is caused by the difference in line endings.

    Is there a way to call console.editfile() so that it won't do any post-processing of the file?

    Also, I'm a little unclear on why the underlying C++ methods would change the line endings to \r\n on Linux. Could that be a bug, or is it intended behavior?

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Sun Apr 27 21:26:43 2025
    Re: File: writeln() and line endings
    By: Nightfox to Digital Man on Sun Apr 27 2025 05:27 pm

    In my test, after creating id_rsa using console.editfile(), SSH fails to authenticate me, which seems to me is caused by the difference in line endings.

    Is there a way to call console.editfile() so that it won't do any post-processing of the file?

    Also, I'm a little unclear on why the underlying C++ methods would change the line endings to \r\n on Linux. Could that be a bug, or is it intended behavior?

    That is intended behavior. I'll look into retaining the line-ending style on edited text files.
    --
    digital man (rob)

    Synchronet/BBS Terminology Definition #60:
    PET = Personal Electronic Transactor (Commodore computer)
    Norco, CA WX: 54.2øF, 78.0% humidity, 4 mph W wind, 0.00 inches rain/24hrs
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Digital Man@VERT to Nightfox on Sun Apr 27 21:36:29 2025
    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Sun Apr 27 2025 09:26 pm

    Re: File: writeln() and line endings
    By: Nightfox to Digital Man on Sun Apr 27 2025 05:27 pm

    In my test, after creating id_rsa using console.editfile(), SSH fails to authenticate me, which seems to me is caused by the difference in line endings.

    Is there a way to call console.editfile() so that it won't do any post-processing of the file?

    Also, I'm a little unclear on why the underlying C++ methods would change the line endings to \r\n on Linux. Could that be a bug, or is it intended behavior?

    That is intended behavior. I'll look into retaining the line-ending style on edited text files.

    Each editor actually has this behavior configured in SCFG:
    "Expand Line Feeds to CRLF" - how is yours set?
    --
    digital man (rob)

    Steven Wright quote #28:
    The hardness of the butter is proportional to the softness of the bread.
    Norco, CA WX: 54.0øF, 78.0% humidity, 4 mph W wind, 0.00 inches rain/24hrs
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Mon Apr 28 09:44:25 2025
    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Sun Apr 27 2025 09:26 pm

    Also, I'm a little unclear on why the underlying C++ methods would change
    the line endings to \r\n on Linux. Could that be a bug, or is it intended
    behavior?

    That is intended behavior. I'll look into retaining the line-ending style on edited text files.

    For my test, I was trying it when id_rsa is a new file (I had made a backup of my original), so it was a new file.

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Nightfox@VERT/DIGDIST to Digital Man on Mon Apr 28 09:47:38 2025
    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Sun Apr 27 2025 09:36 pm

    Also, I'm a little unclear on why the underlying C++ methods would change
    the line endings to \r\n on Linux. Could that be a bug, or is it intended
    behavior?

    That is intended behavior. I'll look into retaining the line-ending style
    on edited text files.

    Each editor actually has this behavior configured in SCFG: "Expand Line Feeds to CRLF" - how is yours set?

    Mine is set to "Yes". I guess that would explain it.

    That has been in place for SlyEdit for quite a while now.. I'm not sure it would be best to change it, or leave it and make a workaround.

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Mon Apr 28 11:49:27 2025
    Re: File: writeln() and line endings
    By: Nightfox to Digital Man on Mon Apr 28 2025 09:47 am

    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Sun Apr 27 2025 09:36 pm

    Also, I'm a little unclear on why the underlying C++ methods would change
    the line endings to \r\n on Linux. Could that be a bug, or is it intended
    behavior?

    That is intended behavior. I'll look into retaining the line-ending style
    on edited text files.

    Each editor actually has this behavior configured in SCFG: "Expand Line Feeds to CRLF" - how is yours set?

    Mine is set to "Yes". I guess that would explain it.

    That has been in place for SlyEdit for quite a while now.. I'm not sure it would be best to change it, or leave it and make a workaround.

    Try changing and seeing what if any negative side effects result?
    --
    digital man (rob)

    This Is Spinal Tap quote #16:
    David St. Hubbins: I believe virtually everything I read...
    Norco, CA WX: 62.3øF, 62.0% humidity, 5 mph WNW wind, 0.00 inches rain/24hrs ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Mon Apr 28 12:53:18 2025
    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Mon Apr 28 2025 11:49 am

    Each editor actually has this behavior configured in SCFG: "Expand
    Line Feeds to CRLF" - how is yours set?

    Mine is set to "Yes". I guess that would explain it.

    That has been in place for SlyEdit for quite a while now.. I'm not sure it
    would be best to change it, or leave it and make a workaround.

    Try changing and seeing what if any negative side effects result?

    I've enabled that. So far I don't see any negative side effects..

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Mon Apr 28 14:25:58 2025
    Re: File: writeln() and line endings
    By: Nightfox to Digital Man on Mon Apr 28 2025 12:53 pm

    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Mon Apr 28 2025 11:49 am

    Each editor actually has this behavior configured in SCFG: "Expand
    Line Feeds to CRLF" - how is yours set?

    Mine is set to "Yes". I guess that would explain it.

    That has been in place for SlyEdit for quite a while now.. I'm not sure it
    would be best to change it, or leave it and make a workaround.

    Try changing and seeing what if any negative side effects result?

    I've enabled that. So far I don't see any negative side effects..

    Double-check whether messages posted with SlyEdit configured in that manner have LF or CRLF terminated lines. By standard, SMB message text is supposed to be CRLF-terminated, but it might not be guaranteed when using an editor that terminates lines with LF only and that "Expland Line Feeds" option is disabled. Or maybe LF-terminated message text is okay now - I don't remember.
    --
    digital man (rob)

    Sling Blade quote #20:
    Doyle: Hey is this the kind of retard that drools and rubs shit in his hair? Norco, CA WX: 66.7øF, 56.0% humidity, 2 mph W wind, 0.00 inches rain/24hrs
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Mon Apr 28 15:18:40 2025
    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Mon Apr 28 2025 02:25 pm

    Double-check whether messages posted with SlyEdit configured in that manner have LF or CRLF terminated lines. By standard, SMB message text is supposed to be CRLF-terminated, but it might not be guaranteed when using an editor that terminates lines with LF only and that "Expland Line Feeds" option is disabled. Or maybe LF-terminated message text is okay now - I don't remember.

    When configured with 'Expand line feeds to CRLF' was false, SlyEdit saved my message with just a \n. My last message posted here was like that. I've made an update to SlyEdit (my test version) to try to ensure it seaves messages with CRLF line endings.

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Mon Apr 28 15:58:59 2025
    Re: File: writeln() and line endings
    By: Nightfox to Digital Man on Mon Apr 28 2025 03:18 pm

    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Mon Apr 28 2025 02:25 pm

    Double-check whether messages posted with SlyEdit configured in that manner have LF or CRLF terminated lines. By standard, SMB message text is supposed to be CRLF-terminated, but it might not be guaranteed when using an editor that terminates lines with LF only and that "Expland Line Feeds" option is disabled. Or maybe LF-terminated message text is okay now - I don't remember.

    When configured with 'Expand line feeds to CRLF' was false, SlyEdit saved my message with just a \n. My last message posted here was like that. I've made an update to SlyEdit (my test version) to try to ensure it seaves messages with CRLF line endings.

    You probably shouldn't need to change SlyEdit. If CRLFs are absolutely required by Synchronet, it should do that expansion from LF to CRLF when necessary (I think happens upon message *display* now).
    --
    digital man (rob)

    Steven Wright quote #15:
    Depression is merely anger without enthusiasm.
    Norco, CA WX: 66.9øF, 57.0% humidity, 18 mph WSW wind, 0.00 inches rain/24hrs ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Mon Apr 28 18:15:59 2025
    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Mon Apr 28 2025 03:58 pm

    When configured with 'Expand line feeds to CRLF' was false, SlyEdit saved
    my message with just a \n. My last message posted here was like that.
    I've made an update to SlyEdit (my test version) to try to ensure it seaves
    messages with CRLF line endings.

    You probably shouldn't need to change SlyEdit. If CRLFs are absolutely required by Synchronet, it should do that expansion from LF to CRLF when necessary (I think happens upon message *display* now).

    Ah, I won't change SlyEdit to do that then.

    Nightfox

    ---
    þ Synchronet þ Digital Distortion: digitaldistortionbbs.com
  • From Digital Man@VERT to Nightfox on Mon Apr 28 20:27:10 2025
    Re: File: writeln() and line endings
    By: Nightfox to Digital Man on Mon Apr 28 2025 06:15 pm

    Re: File: writeln() and line endings
    By: Digital Man to Nightfox on Mon Apr 28 2025 03:58 pm

    When configured with 'Expand line feeds to CRLF' was false, SlyEdit saved
    my message with just a \n. My last message posted here was like that.
    I've made an update to SlyEdit (my test version) to try to ensure it seaves
    messages with CRLF line endings.

    You probably shouldn't need to change SlyEdit. If CRLFs are absolutely required by Synchronet, it should do that expansion from LF to CRLF when necessary (I think happens upon message *display* now).

    Ah, I won't change SlyEdit to do that then.

    Yeah, it'd be best if the editor didn't really matter. I probably should just get rid of that "Expand line feeds" config option since we should always convert the edited file to expected format when needed.
    --
    digital man (rob)

    Synchronet "Real Fact" #78:
    Synchronet Match Maker had at one time over 4000 profiles of men and women Norco, CA WX: 58.5øF, 71.0% humidity, 6 mph W wind, 0.00 inches rain/24hrs
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net